I have one query.
My friend made this solution wherein he found all the masks whose sum was (total/k) and pushed them in a vector.
After that he did this method of checking.
bool flag = false;
for(int i=0; i<test.size(); i++)
{
int cur = test[i];
int cnt = 1;
for(int j=0; j<test.size(); j++)
{
if((cur & test[j]) == 0)
{
cur |= test[j];
cnt++;
}
}
Link: CodeChef: Practical coding for everyone
Can anyone explain me how does this method covers all the subsets of choosing ākā masks?
I know that a recursive method of finding ākā masks will surely give the correct answer but how does this method do that?
Any help is appreciated.
It is really really disappointing to see solutions implementing bruteforce being accepted. Not just that, even wrong solutions are accepted which fail in simple test cases.
I made an array of all bits configurations with sum S/k(of course,if S%k==0) and used recursive function to choose the configuration for my k-th follower,than for the (k-1)-th.Also to boost my time ,I made some improvements such as taking individually the configurations of 1 and 2 elements(because those pairs are unique).
I think I submitted around 30 code sources,before I got 100 points.My question is how cand you say that O(k * (2^n) * n) for EACH TESTCASE can get AC?That complexity takes around 1s for each test caseā¦
From now on please give a solution that really fits in the worst testcases or make the constraints lower.Itās not nice to see that some stupid optimizations give you 100 points.
Iāll let my source code here,if someone is interested in it. CodeChef: Practical coding for everyone
First i checked if dividing in subsets of appropriate sum is possible or notā¦ then I arranged the array in decreasing order, and took the first and searched for possible partners in its subgroup through the arrayā¦ if i dont get it i jumped to the next in array and checked the whole array again for partnersā¦ If i would find a subsetā¦ i will mark all its elements as taken and count++ā¦ in the check if count is equal to kā¦
Now the problem is I got 80 points for itā¦ WA for only 1 testcase in 4 of 20 pointā¦ Any help of any kind would be appreciatedā¦ Thanks
@ishaangupta it actually isnāt trying to choose all the possibilities, it just tries to find whether the required subset is present.
The entire thing would be like this:
You have a vector with all the masks.
Any 2 masks can be used together only when both have no element common, since one Sanskar can be given to only one follower. This is checked using the bitwise &.
Further, the condition for having found a successful subset is that- all the sanskars have been chosen, and K values are present in the subset selected, this is checked in the if using the 1<<n - 1 and other expression.
The flow would be of this sort,
First the outer for loop selects a starting element.
The inner loop selects the values which are ācompatibleā with the current selection, I.e. which do not use sanskars already is use, and after finding these values, updates the cur variable to make notice of this addition of a value.
And then basically it goes through all values, doing the same thing. If there are n sanskars, then the number ((1<<n)-1) simply is a series of 1s, it is the number corresponding to the case when each and every Sanskar has been used.
Eg if n is 4, then it would be 1111, which corresponds to the selection of all 4 sanskars.
Using this method, if at any point the required condition is reached, we break after setting a flag.
can any one please share the solution, which is implemented of editorial . Because i have some doubts in that like what is the size of ādpā and how to initialize it?
Thanks
can anyone tell me why donāt we do sum of all n intensity and if sum%by k followers == 0 then ans is YES otherwise NO.
I only passed starting 2 test cases why this logic is not correct according the statement given into problem.
can anyone tell me why donāt we do sum of all n intensity and if sum%by k followers == 0 then ans is YES otherwise NO.
I only passed starting 2 test cases why this logic is not correct according the statement given into problem.