QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#830277 | #4283. Power of XOR | hicgnliaw | WA | 1ms | 4092kb | C++14 | 1.4kb | 2024-12-24 17:47:57 | 2024-12-24 17:47:57 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ppc(x) __builtin_popcount(x)
using namespace std;
const ll md = 1e9+7;
ll fp(ll x,int p = md-2){
ll res = 1;
while(p){
if(p&1)res = res*x%md;
x = x*x%md;
p>>=1;
}
return res;
}
ll a[50],bs[50] = {1},ji[50],jv[50],jsz,cc[50],f[45][1<<19],jx;
int n,K,id[50];
void dfs(int p,ll v){
if(p==jsz+1){
cc[ppc(v)]++;
return;
}
dfs(p+1,v);
dfs(p+1,v^ji[p]);
}
bool cmp(int x,int y){
return jv[x]<jv[y];
}
int main(){
for(int i = 1;i<44;i++)bs[i] = bs[i-1]<<1;
scanf("%d%d",&n,&K);
ll apw = 1;
for(int i = 1;i<=n;i++){
scanf("%lld",&a[i]);
for(int j = 1;j<=jsz;j++){
if(a[i]&jv[j])a[i]^=ji[j];
}
if(a[i]){
ji[++jsz] = a[i];
id[jsz] = jsz;
jv[jsz] = *(upper_bound(bs,bs+44,a[i])-1);
for(int j = 1;j<jsz;j++){
if(ji[j]&jv[jsz])ji[j]^=ji[jsz];
}
jx|=jv[jsz];
}else apw = apw*2%md;
}
ll ans = 0;
if(jsz<=25)dfs(1,0);
else{
sort(id+1,id+jsz+1,cmp);
ll nv,np;
int cj = 0;
for(int i = 1,p;i<=jsz;i++){
nv = 0;
p = ji[id[i]];
cj = 0;
for(int j = 0;j<44;j++){
if(!(jx&(1LL<<j)))nv|=((ji[p]>>j)&1)<<(cj++);
}
np = 1<<cj;
for(int j = i;j>1;j--){
for(int k = 0;k<np;k++){
(f[j][k]+=f[j-1][k^nv])%=md;
}
}
(f[1][nv]+=1)%=md;
}
for(int i = 1;i<=jsz;i++){
for(int k = 0;k<np;k++){
(cc[i+ppc(k)]+=f[i][k])%=md;
}
}
}
for(int i = 1;i<=44;i++)(ans+=fp(i,K)*cc[i])%=md;
printf("%lld\n",ans*apw%md);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4092kb
input:
3 2 1 2 3
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
2 1000000000 1 2
output:
140625003
result:
ok 1 number(s): "140625003"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
3 4 21 31 15
output:
1076
result:
ok 1 number(s): "1076"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4088kb
input:
4 10 21 16 23 30
output:
3504120
result:
ok 1 number(s): "3504120"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
5 795325759 23 18 18 15 24
output:
398580583
result:
ok 1 number(s): "398580583"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
input:
6 425010546 15190825693299 11021868218180 10853490476696 16489831131502 15731786397897 1859285400474
output:
899135263
result:
wrong answer 1st numbers differ - expected: '226806798', found: '899135263'