#include<bits/stdc++.h>
using namespace std; #define ll long long #define vi vector #define mod 1e9+7 #define ff first #define ss second #define ins insert #define endl “\n” #define pie_op ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define tc int t;cin>>t;while(t–) #define pb push_back #define input(n) ll arr[n];for(int i1=0;i1<n;i1++)cin>>arr[i1]
By seeing some accepted solutions
they used unordered_map instead of map
and ( == 3 ) condition was changed by ( % 5 != 0 )
even if u use (==3) with unordered_map it will give wrong answer .
solution got accepted when i changed map to unordered_map and (==3) to ( %5 != 0)
Why ? Mysterious , Isn’t it ?
Unordered map in c++ seems pretty messed up.
I tried a lot of things with your code, including suggestions given here(LINK) but to no success.
I would love to understand more about this issue.
is unordered map non deterministic?
try this: #include <bits/stdc++.h>
using namespace std;
typedef long long L;
L func(L arr[], int n)
{
L result = 0;
L x, sum;
for (L i = 0; i < 63; i++) {
sum = 0;
x = (1 << i);
for (L j = 0; j < n; j++) {
if (arr[j] & x)
sum++;
}
if ((sum % 5) != 0)
result |= x;
}
return result;
}
int main()
{
int t;
cin>>t;
while(t–){
L n;
cin>>n;
L arr[n];
for(L i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<func(arr,n)<<endl;
}
}