competitive..

Pages: 12
@humanbeing yes
@helpinghand i have read that..
Can any one tell where i am going wrong in this code for NO MINIMUM NO MAXIMUM problem:
It is okay if it gives me TLE but it is giving me WA.

My code:

#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007

int ans[10000];

int combinationUtil(int arr[], int data[], int start, int end, int index, int r);

int compare (const void * a, const void * b)
{ return ( *(int*)a - *(int*)b ); }


void printCombination(int arr[], int n, int r, int count1)
{
int data[r];
qsort (arr, n, sizeof(int), compare);

ans[count1] = combinationUtil(arr, data, 0, n-1, 0, r);

if(count1>=1)
{
ans[count1] = ans[count1]/ans[count1-1];
}

cout<<ans[count1]<<endl;
}

long long int prod = 1;

int combinationUtil(int arr[], int data[], int start, int end, int index, int r)
{

if (index == r)
{

sort(data, data+r);
for(int i=1;i<r-1;i++)
{
prod = prod*data[i];
}

prod = prod%mod;

return 0;
}


for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r);


// Remove duplicates
while (arr[i] == arr[i+1])
i++;
}

return prod;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
int count1=0;
while(t--)
{
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}

printCombination(a, n, m, count1);

count1++;
}
return 0;
}
Last edited on
Did anyone completed any question after first two in long challenge?
can anyone help me with this

You are given a string S of lowercase English letters with length N. You are allowed to (but don't have to) choose one index in this string and change the letter at this index to any other lowercase English letter. The cost of this operation is the absolute value of the difference of ASCII values of the new letter and the original letter; let's denote it by X.

Next, consider the number of pairs of indices (i,j) in the resulting string (the string after changing one letter, or the original string if no letter was changed) such that 1≤i<j≤N and Si<Sj. Let's denote it by Y.

Find the minimum possible value of X+Y.
Last edited on
I have done the No Strings Attached.If anyone has solution of questions after question-4 [even partial is okay] then pm me i will tell him the logic for No Strings Attached[or will send the code]
Last edited on
Any one solved No Strings Attached ??
i have partially accepted solution for both NSA and NMNMX.
if anyone has fully accepted solution of any and wants partial of the other , DM me
Since everyone was asking the logic for no strings attached question i will share here some of the hints:
first understand the question.
You can change the letter[or not] in the given string.
So if you are given a string with consecutive letters then your answer is just min(y),
but if some of your character is not in consecutive then change it to min possible and in that case your answer is min(x+y)

Hint: for comparision you can use balanced binary search tree [ To avoid TLE problems]
[If you know c++ -stl then you can use map which is built based on balanced bst only]
Last edited on
Is there any thread going on for the discussion of the 3rd and 4th problem. Kindly share the link.
@humanbeing please explain how would you do to calculate x
please help anyone?:(
How do I find modulo of large number in NMNMX? I have got the logic but I find it difficult to find the modulo at the end. Please help anyone..
Topic archived. No new replies allowed.
Pages: 12