My issue
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n;
cin>>n;
unordered_map<int,int> mp1;
vector<int> v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
mp1[v[i]^v[j]]++;
}
}
long long ans = 0;
for(auto it:mp1){
ans += (it.second)*(it.second-1)*1ll;
}
ans = ans*4;
cout<<ans<<"\n";
}
}
For question number 4 Xometry easy version above code gives TIME LIMIT EXCEEDED why?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
long long ans = 0;
unordered_map<int,long long> mp;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
ans+=mp[v[i]^v[j]]++;
}
}
cout<<ans*8*1ll<<"\n";
}
}
Problem Link: Xometry (Easy Version) Practice Coding Problem