QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#304145 | #5827. 异或图 | kkkgjyismine4 | 10 | 24ms | 20180kb | C++14 | 3.9kb | 2024-01-13 15:08:04 | 2024-01-13 15:08:05 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
int N,M,mp[20][20],cnt[1<<20],Lian[1<<20],fa[20];
ll f[15000000],A[20],g[1<<20],C,pw[10003],comb[404][404],dp1[1<<20],dp2[1<<20];int p[20],tot,popcnt[1<<20];
int find(int r){return r==fa[r]?r:(fa[r]=find(fa[r]));}
void add(ll &x,const ll y){if((x+=y)>=mod)x-=mod;}
void sub(ll &x,const ll y){if((x+=(mod-y))>=mod)x-=mod;}
void dfs(int u,int mask,int now,int w,int op,int cnt1,ll v,ll &res){
if(u==tot){if((popcnt[now]&1)==op){if(cnt1)res=(res+v*pw[(cnt1-1)*w])%mod;else if(w==0)add(res,v);}return;}
if(!((mask>>u)&1)){
if(w)v=v*(((A[p[u]]&((1ll<<w)-1ll))+1ll)%mod)%mod;
dfs(u+1,mask,now,w,op,cnt1,v,res);
}else{
dfs(u+1,mask,now,w,op,cnt1+1,v,res);
if(w)v=v*(((A[p[u]]&((1ll<<w)-1ll))+1ll)%mod)%mod;
dfs(u+1,mask,(now|(1<<u)),w,op,cnt1,v,res);
}
}
ll mn[1<<20];
void init(int mask){
if(!mask)return;mn[mask]=1e18;
for(int i=0;i<N;++i)fa[i]=i;
for(int i=0;i<N;++i)if((mask>>i)&1)for(int j=i+1;j<N;++j)if(((mask>>j)&1)&&mp[i+1][j+1])fa[find(i)]=find(j),++cnt[mask];
int pos=-1;for(int i=0;i<N;++i)if((mask>>i)&1)pos=i;Lian[mask]=1;
for(int i=0;i<N;++i)if(((mask>>i)&1)&&find(i)!=find(pos))Lian[mask]=0;
tot=0;for(int i=0;i<N;++i)if((mask>>i)&1)p[tot++]=i+1,mn[mask]=min(mn[mask],A[i+1]);
for(int i=60;i>=0;--i){
int m=0,Xor,cnt1;for(int j=0;j<tot;++j)m|=(((A[p[j]]>>i)&1ll)<<j);
dfs(0,m,0,i,((C>>i)&1ll),0,1ll,g[mask]);
if((popcnt[m]&1)!=((C>>i)&1ll))break;
} mn[mask]%=mod;
}
int pw3[20];
int getop(int x,int y){return ((x/pw3[y])%3);}
bool cmp(int x,int y){
if(A[x]==A[y])return x<y;
return A[x]<A[y];
}
int val3[1<<20];
int Add[1<<15];
ll dp3[1<<15];
int main() {
scanf("%d%d%lld",&N,&M,&C);pw[0]=pw3[0]=1;for(int i=1;i<=N;++i)pw3[i]=pw3[i-1]*3;for(int i=1;i<=10000;++i)pw[i]=pw[i-1]*2ll%mod;
for(int i=0;i<=400;++i)comb[i][0]=1ll;for(int i=1;i<=400;++i)for(int j=1;j<=i;++j)comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
for(int i=0;i<(1<<N);++i)for(int j=0;j<N;++j)if((i>>j)&1)val3[i]+=pw3[j];
for(int i=1;i<(1<<N);++i)popcnt[i]=popcnt[i>>1]+(i&1);for(int i=1;i<=N;++i)scanf("%lld",&A[i]);
for(int i=1;i<=M;++i){int u,v;scanf("%d%d",&u,&v);mp[u][v]=mp[v][u]=1;}if(C==0ll)g[0]=1ll;
for(int i=0;i<(1<<N);++i)init(i);int mx=0;for(int i=0;i<N;++i)mx+=2*pw3[i];ll res=0ll,res1=0ll;f[0]=1ll;
for(int i=0;i<(1<<N);++i){
if(!i)continue;
int mn=-1;for(int j=0;j<N;++j)if((i>>j)&1){mn=j;break;}
int All=(i^(1<<mn));
for(int k=0;k<=cnt[i];++k){
if(k&1)sub(dp1[i],comb[cnt[i]][k]);
else add(dp1[i],comb[cnt[i]][k]);
}dp2[i]=dp1[i];
for(int j=All;;j=((j-1)&All)){
int now=(j^(1<<mn)),Other=(i^now);
if(now&&Other)dp2[i]=(dp2[i]+(mod-dp2[now])*dp1[Other])%mod;
if(!j)break;
}
}
for(int i=1;i<(1<<N);++i){
dp3[i]=dp2[i]*((mn[i]+1ll)%mod)%mod;
if(popcnt[i]&1){
int id=-1;
for(int j=0;j<N;++j)if((i>>j)&1){if(id==-1||A[id]>A[j])id=j;Add[i]+=pw3[j];}
Add[i]+=pw3[id];
}else for(int j=0;j<N;++j)if((i>>j)&1)Add[i]+=pw3[j];
}
for(int i=0;i<mx;++i){
if(!f[i])continue;
int pos=-1,t=i,v,fl=1,nowt=0;
for(int j=0;j<N;++j){
v=getop(i,j);
if(v==2){pos=j;t-=2*pw3[j];break;}
}
int Could=0,Mask=0,t1=0,mx=-1;
for(int j=0;j<N;++j){
v=getop(i,j);
if(!v)fl=0,nowt|=(1<<j);
if(v==2)Mask|=(1<<j);
if(v==1&&cmp(pos+1,j+1))Could|=(1<<j);
if(v==1)t1|=(1<<j),mx=j;
}
if(popcnt[t1]&1)continue;
if(!nowt)continue;
int Low=(nowt&-nowt);
nowt^=Low;
for(int s=nowt;;s=((s-1)&nowt)){
int nxt=Add[s|Low]+i;
if(popcnt[s]&1)f[nxt]=(f[nxt]+f[i]*dp3[s|Low])%mod;
else f[nxt]=(f[nxt]+f[i]*dp2[s|Low])%mod;
if(!s)break;
}
}
for(int i=1;i<=mx;++i){
if(!f[i])continue;
int pos=-1,t=i,v,fl=1;
int Could=0,Mask=0,t1=0,mx=-1;
for(int j=0;j<N;++j){
v=getop(i,j);
if(!v)fl=0;
if(v==2)Mask|=(1<<j);
}
if(fl)res=(res+f[i]*g[Mask])%mod;
}
cout<<res<<endl;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 18068kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
86
result:
wrong answer 1st numbers differ - expected: '44', found: '86'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 10
Accepted
Test #47:
score: 10
Accepted
time: 24ms
memory: 20180kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
231790380
result:
ok 1 number(s): "231790380"
Test #48:
score: 0
Accepted
time: 0ms
memory: 16176kb
input:
11 0 101435837408688522 638776638580507479 933944392115323974 19098604312360490 142362319980029593 419910251764515410 275591812677260089 770239593400917018 928344484461634421 67340905784404712 378109786925249078 110881245457449811
output:
242383534
result:
ok 1 number(s): "242383534"
Test #49:
score: 0
Accepted
time: 0ms
memory: 15884kb
input:
9 0 100988561775675251 622570387572403506 684352103903274038 784649864569409753 270298495621205212 56183537059869110 346856482529145989 86639702870530669 607198038565138736 14747634008501988
output:
20893166
result:
ok 1 number(s): "20893166"
Test #50:
score: 0
Accepted
time: 3ms
memory: 16168kb
input:
10 0 839910859917247463 611237879350518457 292219463776059962 548211857317940894 822255554598388425 335628456629874391 774414280870858683 882480367082748768 654587410087321403 74330774886125511 22894883233341926
output:
61697734
result:
ok 1 number(s): "61697734"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%