CHANDF - EDITORIAL

Send link to your solution.

https://www.codechef.com/viewsolution/33038243

Try the above case where I have given X = Y = 10^{11}.
It is mentioned above.

@harshil21 Plz review my code.I have got 40 points for this but cannot understand what test case may go wrong for this:

https://www.codechef.com/viewsolution/33038356

Try

2
7216784 5118850 23889 26008
475288 411705 32322 32875

Answers expected:

24466
32441

Yes the code gives these expected answers as stated by you.
for test case 1: 32000
for test case 2: 26324

I have checked your code from link and your code fails on the given test case.
If not try generating some random test cases and compare with brute force solution to verify it.

thanks a lot for sharing this.

@harshil21
https://www.codechef.com/viewsolution/33040617
For X=Y= 10^11
my code give z =98924161024
maxProduct = 9215275236218372096
while tester code gives 99999997952
with maxProduct = 1864302449427218432
which is less .

Why unsigned long long datatype is giving wrong answer in subtask 2 in this problem??
CodeChef: Practical coding for everyone when i changed it to long long it it passes.

There was a problem in the test data as the answer could overflow while checking the function for max Value, which is described the above comments.
But, as it was mentioned in the question that the function at the answer does not exceed the limits of long long integer, the problem accepts all the solution with long long integer.

https://www.codechef.com/viewsolution/33010382

@harshil21 I am trying this logic for 2nd subtask i.e. 40 pts. But it shows WA. And I am unable to think of a Testcase where it fails.

There is an error in the expected result for the data:
x=1079300 and y=15684
fun(x,y,z)=(x&z)*(y&z)

my answer is 15684
according to which the value of function becomes 224908560

and for your answer , i.e.16708,
the value of function becomes 5309712, which is less than my functions value.

1 Like

It was supposed to be your answer* :sweat_smile: not our answer.
The “answer” is the correct output.

Here, .to_ulong() gives WA as it is showing some errors for X,Y \ge 10^{9}.
Try using bit-wise operations mentioned above in the editorial(link) .

#include <bits/stdc++.h>
using namespace std;
vector decTobin(int n){
vector a;
while(n!=0){
a.insert(a.end(),n%2);
n=n/2;
}
return a;
}
int deci(vector a){
int n=0;
int j=0;
for(int i=a.size()-1;i>=0;i–){
n+=a[i]*pow(2,j++);
}
return n;
}
int main() {
int test;
cin>>test;
while(test–){
int x,y,l,r;
cin>>x>>y>>l>>r;
int t=x;
x=x>y?x:y;
if(y==x){
y=t;
}
vector xbinary=decTobin(x);
vector ybinary=decTobin(y);
vector lbinary=decTobin(l);
vector rbinary=decTobinÂŽ;
while(lbinary.size()!=rbinary.size()){
lbinary.insert(lbinary.begin(),0);
}
while(ybinary.size()!=xbinary.size()){
ybinary.insert(ybinary.begin(),0);
}

	if(rbinary.size()!=xbinary.size()){
		if(rbinary.size()>xbinary.size()){
			while(!xbinary.size()==rbinary.size()){
			ybinary.insert(ybinary.begin(),0);
			xbinary.insert(xbinary.begin(),0);
		}
	}
		else{
			while(xbinary.size()!=rbinary.size()){
			lbinary.insert(lbinary.begin(),0);
			rbinary.insert(rbinary.begin(),0);
		}
	}		
	}
	vector<int> res(rbinary.size()) ;
	int i=0;
	while(lbinary[i]==rbinary[i]){
		res[i]=lbinary[i];
		i++;
	}
	vector<int> values;
	for(int j=i;j<lbinary.size();j++){
		if(rbinary[j]==0){
			res[j]=0;
			if(j==lbinary.size()-1){
				for(int l=i;l<lbinary.size();l++){
				if((xbinary[l]==0) && (ybinary[l]==0) && (lbinary[l]==0)){
				res[l]=0;
			}
		}
		values.insert(values.begin(),deci(res));
			}
			continue;
		}
		res[j]=0;
		for(int k=j+1;k<lbinary.size();k++){
			res[k]=1;
		}
		for(int th=j;th<res.size();th++){
			if((xbinary[th]==0) && (ybinary[th]==0) && (lbinary[th]==0)){
				res[th]=0;
			}
		}
		values.insert(values.begin(),deci(res));
		res[j]=1;
	}
	values.insert(values.begin(),l);
	values.insert(values.begin(),r);
	sort(values.begin(), values.end());
	for(int i=0;i<values.size();i++){
		cout<<values[i]<<' ';
	}
	cout<<endl;
	int maxx=0;
	int maxi=0;
	for(int i=0;i<values.size();i++){
		int t=(x&values[i])*(y&values[i]);
		if(t>maxx){
			maxx=t;
			maxi=values[i];
		}
	}
	cout<<maxi;
}
return 0;

}
can anybode please check and tell me what’s wrong in this code.

https://www.codechef.com/viewsolution/33031560

check in this submission

1 Like

It means that we need to match the errors(overflow) produced by model solutions.
Doesn’t sound good :sweat:.

Most of my friends has used .to_ulong() and they are getting AC.

No, that’s not the case.
The test data is made in such a way that it does not contain any overflows, but there is only 1 case in files for Subtask 2 which chance of overflow under some given instances(if not handled well).
But as the statement mentioned, solution had to be such that answer fits in the limits of long long integer.
Sorry for the inconvenience.