ECPC10A - Editorial

x = a ^ b, a < b,
lets k is msb bit of a,
now x > max(a, b) iff kth bit of b is 0.

for each Ai , kth bit of Ai is 0, then we have to count Aj such that k is msb bit of Aj.

2 Likes

Line #7 for j in range(x):
you need to use
for j in range(i, x):

If it still doesn’t work then sort the list then use
if (arr[i] ^ arr[j]) > arr[j]: count += 1

Got it. Thanks

getting wrong answer and no one is successful solution in python.
check here => CodeChef: Practical coding for everyone

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

int main()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
unsigned int t,n=0,count=0;
unsigned c=0;
cin>>t;
while(t–)
{
cin>>n;
vector v(n,0);
for(int i=0;i<n;i++)
cin>>v[i];
sort(v.begin(),v.end());
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
c=v[i]^v[j];
if(c>v[j])
{
// if(c>v[j])
++count;
}
}
}
cout<<count<<"\n";
count=0;
// c=0;

}
// your code goes here
return 0;

}

I have fixed the code, if any questions about it ask me
` #include <bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int t, n=0, count=0; // Changed from unsigned int to int, No need to do it, just did it for debugging sakes.
unsigned c=0;

cin >> t;
while(t--) {
    int n; // Never initialized n
    cin >> n;
    
    vector <int> v; // Wrong method of initialization of a vector, fixed it.
    
        for(int i=0;i<n;i++) { // You were missing braces here
            int inp;
            cin >> inp;
            v.push_back(inp);// cin>>v[i]; This method is used for arrays, use the corrected one for vectors; It will add a element at the end of the vector.
    }
    
    sort(v.begin(),v.end());
    
    for(int i=0;i<n-1;i++) {
        for(int j=i+1;j<n;j++) {
            
            c = v[i] ^ v[j];
            if(c > v[j]) count ++;
        }
    }
    cout << count << "\n";
    count = 0;
}
return 0;

}

1 Like

i had the similar approach got :white_check_mark:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll t;
	cin>>t;
	while(t--)
	{
     ll n;
     cin>>n;
     ll arr[n];
     for(ll i=0;i<n;i++)
      cin>>arr[i];
     ll X,cnt=0;
	 for(ll i=0;i<n;i++)
	 {
	 	for(ll j=i;j<n;j++)
	 	{
	 	 X = arr[i]^arr[j];
	 	
	 	if( X>arr[i] && X>arr[j])
	   	cnt++;
		}
	  } 
	  cout<<cnt<<endl;
	}
return 0;
}

1 Like

Thanks buddy, :hugs: you just did wonderful work…
Bhagwam aapko arabpati bnaaye😁

2 Likes

Thanks Ashish :cat2:

1 Like