We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>#define MOD 1000000007usingnamespacestd;longlongintdp[1001][8192]={0};vector<int>P;voidmake_prime(){boolprime[8192];memset(prime,true,sizeof(prime));for(intp=2;p*p<=8191;p++){if(prime[p]==true){for(inti=p*2;i<=8191;i+=p)prime[i]=false;}}for(inti=2;i<8192;i++){if(prime[i])P.push_back(i);}}intmain(){intt,n,i,l,j,temp;longlongintans=0;make_prime();cin>>t;while(t--){unordered_map<int,int>f;vector<int>v;cin>>n;for(i=0;i<n;i++){cin>>temp;if(!f[temp])v.push_back(temp);f[temp]++;}l=v.size();dp[0][0]=(f[v[0]]+2)/2;dp[0][v[0]]=(f[v[0]]+1)/2;for(i=1;i<l&&i<1001;i++)for(j=0;j<8192;j++)dp[i][j]=((dp[i-1][j]*((f[v[i]]+2)/2))+(dp[i-1][v[i]^j]*((f[v[i]]+1)/2)))%MOD;for(j=0;j<P.size();j++)ans=(ans+dp[l-1][P[j]])%MOD;cout<<ans<<endl;ans=0;memset(dp,0,sizeof(dp));}return0;}MYcodeisalmostsameasyoursbutiamgettingtimeoutforlast4casesrestcasesarecorrect.Canyoutellmewhatistheproblem
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Prime XOR
You are viewing a single comment's thread. Return to all comments →