QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90823 | #5827. 异或图 | zhouhuanyi | 20 | 655ms | 3848kb | C++23 | 3.0kb | 2023-03-25 16:51:13 | 2023-03-25 16:51:15 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 16
#define mod 998244353
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int lowbit(int x)
{
return x&(-x);
}
int n,m,ans,tong[N+1],length,sz[1<<N],F[1<<N],G[1<<N],miner[1<<N],delta[1<<N],delta2[1<<N],dp[N+1][2],dp2[N+1][2];
long long a[N+1],c;
bool E[N+1][N+1];
void dfs(int x,int st,int res)
{
if (!x)
{
Adder(ans,1ll*delta[st]*res%mod);
return;
}
for (int i=x;i>0;i=(i-1)&x)
if ((sz[i]&1)&&lowbit(i)==lowbit(x))
dfs(x^i,st|(1<<(miner[i]-1)),1ll*res*G[i]%mod);
return;
}
int main()
{
//freopen("graph.in","r",stdin);
//freopen("graph.out","w",stdout);
int x,y,cnt;
n=read(),m=read(),c=read();
for (int i=1;i<(1<<n);++i) sz[i]=sz[i-lowbit(i)]+1;
for (int i=1;i<=n;++i) a[i]=read();
for (int i=1;i<=m;++i) x=read(),y=read(),E[x][y]=E[y][x]=1;
for (int i=0;i<(1<<n);++i)
{
F[i]=1;
for (int j=1;j<=n;++j)
if (i&(1<<(j-1)))
for (int k=j+1;k<=n;++k)
if ((i&(1<<(k-1)))&&E[j][k])
F[i]=0;
}
for (int i=0;i<(1<<n);++i)
{
G[i]=F[i];
for (int j=i;j>0;j=(j-1)&i)
if (lowbit(i)==lowbit(i^j))
Adder2(G[i],-1ll*F[j]*G[i^j]%mod);
}
for (int i=0;i<(1<<n);++i)
for (int j=1;j<=n;++j)
if ((i&(1<<(j-1)))&&(!miner[i]||a[j]<a[miner[i]]))
miner[i]=j;
for (int i=0;i<(1<<n);++i)
{
length=0;
for (int j=1;j<=n;++j)
if (i&(1<<(j-1)))
tong[++length]=a[j];
for (int j=59;j>=0;--j)
{
for (int k=0;k<=length+1;++k) dp[k][0]=dp[k][1]=dp2[k][0]=dp2[k][1]=0;
dp[0][0]=dp2[length+1][0]=1,cnt=0;
for (int k=1;k<=length;++k)
for (int op=0;op<=1;++op)
{
if (tong[k]&(1ll<<j))
{
Adder(dp[k][op],1ll*dp[k-1][op]*((1ll<<j)%mod)%mod);
Adder(dp[k][op^1],1ll*dp[k-1][op]*(((tong[k]&((1ll<<j)-1))+1)%mod)%mod);
}
else Adder(dp[k][op],1ll*dp[k-1][op]*(((tong[k]&((1ll<<j)-1))+1)%mod)%mod);
}
for (int k=length;k>=1;--k)
for (int op=0;op<=1;++op)
{
if (tong[k]&(1ll<<j)) Adder(dp2[k][op^1],1ll*dp2[k+1][op]*(((tong[k]&((1ll<<j)-1))+1)%mod)%mod);
else Adder(dp2[k][op],1ll*dp2[k+1][op]*(((tong[k]&((1ll<<j)-1))+1)%mod)%mod);
}
for (int k=1;k<=length;++k)
if (tong[k]&(1ll<<j))
{
for (int op=0;op<=1;++op) Adder(delta[i],1ll*dp[k-1][op]*dp2[k+1][op^((c>>j)&1)]%mod);
cnt++;
}
if ((cnt&1)!=((c>>j)&1)) break;
if (!j) Adder(delta[i],1);
}
}
delta2[0]=1;
for (int i=0;i<(1<<n);++i)
for (int j=i;j>0;j=(j-1)&i)
if (!(sz[j]&1)&&lowbit(i)==lowbit(j))
Adder(delta2[i],1ll*delta2[i^j]*(a[miner[j]]+1)%mod*G[j]%mod);
for (int i=0;i<(1<<n);++i)
if (!(sz[i]&1))
dfs(((1<<n)-1)^i,0,delta2[i]);
printf("%d\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: 2ms
memory: 3364kb
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: 2ms
memory: 3688kb
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: 2ms
memory: 3688kb
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: 3408kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3688kb
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: 2ms
memory: 3444kb
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: 2ms
memory: 3528kb
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: 2ms
memory: 3460kb
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: 2ms
memory: 3488kb
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: 0ms
memory: 3520kb
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: 2ms
memory: 3524kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3520kb
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: 2ms
memory: 3512kb
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: 3508kb
input:
5 0 12 9 8 14 11 2
output:
3006
result:
ok 1 number(s): "3006"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3508kb
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: 2ms
memory: 3656kb
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:
-1884879921
result:
wrong answer 1st numbers differ - expected: '5392583', found: '-1884879921'
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 655ms
memory: 3848kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
327497430
result:
wrong answer 1st numbers differ - expected: '231790380', found: '327497430'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%