QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322833 | #5827. 异或图 | gao_yc | 20 | 20ms | 4616kb | C++11 | 2.4kb | 2024-02-07 20:33:36 | 2024-02-07 20:33:36 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
const int N=17,S=(1<<15)+10,mod=998244353;
int n,m,p[N],id[N];ll c,a[N];
void upd(ll &x,ll y){x=(x+y)%mod;}
ll qpow(ll a,int x){ll res=1;for(;x;x>>=1,a=a*a%mod) if(x&1) res=res*a%mod;return res;}
ll inv(ll a){return qpow(a,mod-2);}
vector<ll> vs;
ll calc(){
ll res=0,ans,f[2],g[2];
per(i,60,0){
f[0]=1;f[1]=0;int s=0,nc=(c>>i)&1;ans=1;
for(ll val:vs){
g[0]=f[0];g[1]=f[1];
if((val>>i)&1){
++s;
f[0]=(g[1]*((1ll<<i)%mod)%mod+g[0]*((val&(1<<i)-1)%mod+1)%mod)%mod;
f[1]=(g[0]*((1ll<<i)%mod)%mod+g[1]*((val&(1<<i)-1)%mod+1)%mod)%mod;
}
else{
f[0]=g[0]*((val&(1<<i)-1)%mod+1)%mod;
f[1]=g[1]*((val&(1<<i)-1)%mod+1)%mod;
}
ans=ans*((val&(1<<i)-1)%mod+1)%mod;
}
upd(f[0],mod-ans);
if(s) upd(res,f[nc^(s&1)]*inv((1ll<<i)%mod)%mod);
if((s&1)!=nc) break;
if(!i) ++res;
}
return res;
}
ll f[S],g[S],h[S],lh[S],ans;
int main(){
scanf("%d%d%lld",&n,&m,&c);
rep(i,1,n) scanf("%lld",a+i);
iota(p+1,p+n+1,1);sort(p+1,p+n+1,[&](int x,int y){return a[x]<a[y];});rep(i,1,n) id[p[i]]=i;
sort(a+1,a+n+1);
int u,v;while(m--) scanf("%d%d",&u,&v),g[(1<<(id[u]-1))|(1<<(id[v]-1))]=1;
rep(i,0,n-1) rep(j,0,(1<<n)-1) if(j>>i&1) g[j]|=g[j^(1<<i)];
rep(i,0,(1<<n)-1) g[i]^=1;
rep(i,1,(1<<n)-1){
f[i]=g[i];
for(int j=i&(i-1),jj=j;j;j=(j-1)&jj) upd(f[i],g[j]*(mod-f[i^j])%mod);
}
h[0]=1;
rep(i,1,n){
memcpy(lh,h,sizeof(h));memset(h,0,sizeof(h));
rep(s,0,(1<<n)-1)
if(s>>(i-1)&1) upd(h[s^(1<<i-1)],lh[s]);
else{
int sq=(s^((1<<n)-1))&((1<<n)-(1<<i));
for(int j=sq;;j=(j-1)&sq){
int t=j|s;ll nr=lh[s]*f[j|(1<<i-1)]%mod;
if(__builtin_parity(j)) upd(h[t],(a[i]+1)%mod*nr%mod);
else upd(h[t|(1<<i-1)],nr);
if(!j) break;
}
}
}
rep(i,0,(1<<n)-1) if(h[i]){vs.clear();rep(j,1,n) if(i>>(j-1)&1) vs.push_back(a[j]);upd(ans,h[i]*calc()%mod);}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 1ms
memory: 4456kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
44
result:
ok 1 number(s): "44"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4432kb
input:
4 4 6 12 14 14 5 4 2 1 4 3 2 1 2
output:
798
result:
ok 1 number(s): "798"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4308kb
input:
3 3 2 10 4 11 2 1 3 2 1 3
output:
33
result:
ok 1 number(s): "33"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4496kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Accepted
time: 1ms
memory: 4376kb
input:
5 6 14 12 15 13 13 12 3 1 2 4 2 5 2 1 5 3 4 5
output:
21337
result:
ok 1 number(s): "21337"
Test #6:
score: 0
Accepted
time: 1ms
memory: 4496kb
input:
4 5 5 5 2 4 13 2 1 3 4 1 4 4 2 3 2
output:
42
result:
ok 1 number(s): "42"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4356kb
input:
4 4 3 13 7 8 12 4 1 3 1 2 4 4 3
output:
552
result:
ok 1 number(s): "552"
Test #8:
score: 0
Accepted
time: 1ms
memory: 4372kb
input:
4 2 12 1 12 4 11 2 1 3 1
output:
70
result:
ok 1 number(s): "70"
Test #9:
score: 0
Accepted
time: 1ms
memory: 4456kb
input:
5 5 6 10 7 8 2 13 1 5 1 3 2 1 4 3 5 3
output:
1231
result:
ok 1 number(s): "1231"
Test #10:
score: 0
Accepted
time: 1ms
memory: 4388kb
input:
5 7 9 6 7 13 15 12 1 3 5 3 5 2 4 5 4 3 4 1 3 2
output:
6223
result:
ok 1 number(s): "6223"
Test #11:
score: 0
Accepted
time: 1ms
memory: 4452kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 0
Accepted
time: 1ms
memory: 4440kb
input:
3 2 9 10 6 5 1 2 1 3
output:
17
result:
ok 1 number(s): "17"
Test #13:
score: 0
Accepted
time: 1ms
memory: 4452kb
input:
5 5 11 7 9 15 9 9 5 4 5 1 5 2 1 3 3 4
output:
5224
result:
ok 1 number(s): "5224"
Test #14:
score: 0
Accepted
time: 1ms
memory: 4388kb
input:
5 0 12 9 8 14 11 2
output:
3006
result:
ok 1 number(s): "3006"
Test #15:
score: 0
Accepted
time: 1ms
memory: 4356kb
input:
3 1 1 6 10 4 3 1
output:
30
result:
ok 1 number(s): "30"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #16:
score: 0
Wrong Answer
time: 1ms
memory: 4452kb
input:
9 27 705410105529944560 929827299070190972 733413770730537329 473007347105710981 190062421504120247 918561152768663129 196040702922254016 981530663192980241 203295856357272834 337150461958783092 2 8 7 9 8 9 2 3 9 2 2 7 9 5 9 4 4 8 1 7 6 3 6 1 4 1 6 5 2 4 2 1 9 3 9 6 7 3 7 5 5 2 4 5 2 6 3 1 3 8 4 3 8 6
output:
580524414
result:
wrong answer 1st numbers differ - expected: '5392583', found: '580524414'
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 20ms
memory: 4616kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
273474550
result:
wrong answer 1st numbers differ - expected: '231790380', found: '273474550'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%