QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90372 | #5827. 异或图 | ytczy666 | 30 | 31ms | 7372kb | C++14 | 2.9kb | 2023-03-22 20:20:25 | 2023-03-22 20:20:28 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::min;
using std::max;
using std::set;
using std::queue;
using std::sort;
using std::unique;
using std::vector;
using std::pair;
#define ll long long
#define db double
#define inf 0x3f3f3f3f
#define ull unsigned long long
#define F(i,l,r) for(int i=(l);i<=(r);i++)
#define UF(i,l,r) for(int i=(l);i>=(r);i--)
#define mp std::make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define ls(x) x<<1
#define rs(x) x<<1|1
#define pb push_back
inline ll rd(){
ll f=1,x=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return f*x;
}
const int mo=998244353;
inline int qk(int x){return x>=mo?x-mo:x;}
int n,m,pw[15*15],mn[(1<<15)+5],e[(1<<15)+5],f[2][(1<<15)+5],g[2][(1<<15)+5];
int res[(1<<15)+5],tmp[15],dp[2][15];
ll C,a[15],ta[15];
std::unordered_map<int,int>ddp[(1<<15)+5];
void calc(int s){
int N=0;
F(i,0,n-1)if(s>>i&1)ta[N++]=a[i];
UF(d,59,0){
int c=C>>d&1,Sum=0,mul=1,len=0;
ll tot=(1ll<<d+1)-1;
F(i,0,N-1){
if(ta[i]>>d&1)Sum^=1,tmp[len++]=i;
else mul=1ll*mul*((ta[i]&tot)%mo+1)%mo;
}
bool flag=0;
if(Sum!=c)flag=1;
if(len){
F(i,0,len-1){
if(i)c^=1,mul=1ll*mul*((ta[tmp[i-1]]&(tot>>1))%mo+1)%mo;
dp[c][i]=1;dp[c^1][i]=0;
F(j,i+1,len-1)F(o,0,1){
int v0=(1ll<<d)%mo,v1=(ta[tmp[j]]&(tot>>1))%mo+1;
dp[o][j]=qk(1ll*dp[o][j-1]*v0%mo+1ll*dp[o^1][j-1]*v1%mo);
}
res[s]=qk(res[s]+1ll*mul*dp[0][len-1]%mo);
}
}
if(flag)break;
if(d==0)++res[s];
}
}
int main(){
n=rd();m=rd();C=rd();
pw[0]=1;F(i,1,n*n)pw[i]=qk(pw[i-1]+pw[i-1]);
F(i,0,n-1)a[i]=rd();
F(i,1,m){
int u=rd()-1,v=rd()-1;
e[u]|=(1<<v);e[v]|=(1<<u);
}
F(i,0,n-1)mn[1<<i]=i;
F(s,1,(1<<n)-1){
mn[s]=-1;
F(i,0,n-1)if(s>>i&1){
if(mn[s]==-1||a[mn[s]]>a[i])mn[s]=i;
}
}
f[0][0]=g[0][0]=1;
F(s,1,(1<<n)-1){
int Nume=0,P=s&-s;
F(i,0,n-1)if(s>>i&1)Nume+=__builtin_popcount(e[i]&s);
if(!Nume)f[0][s]=1;else f[0][s]=f[1][s]=pw[(Nume>>1)-1];
g[0][s]=f[0][s];g[1][s]=f[1][s];
for(int t=s;t;t=(t-1)&s)if((t&P)&&t!=s){
g[0][s]=qk(g[0][s]-1ll*g[0][t]*f[0][s^t]%mo+mo);
g[0][s]=qk(g[0][s]-1ll*g[1][t]*f[1][s^t]%mo+mo);
g[1][s]=qk(g[1][s]-1ll*g[0][t]*f[1][s^t]%mo+mo);
g[1][s]=qk(g[1][s]-1ll*g[1][t]*f[0][s^t]%mo+mo);
}
}
F(i,1,(1<<n)-1)calc(i);
ddp[0][0]=1;
F(s,0,(1<<n)-1)for(auto e:ddp[s]){
int t=e.fi,w=e.se;
if(w){
int lv=((1<<n)-1)^s,lw=lv&-lv;
for(int t2=lv;t2;t2=(t2-1)&lv)if(t2&lw){
if(__builtin_popcount(t2)&1)ddp[s^t2][t^(1<<mn[t2])]=qk(ddp[s^t2][t^(1<<mn[t2])]+1ll*w*(g[0][t2]-g[1][t2]+mo)%mo);
else ddp[s^t2][t]=qk(ddp[s^t2][t]+1ll*w*(a[mn[t2]]+1)%mo*(g[0][t2]-g[1][t2]+mo)%mo);
}
}
if(!t)break;
}
int ans=0;
F(i,1,(1<<n)-1)ans=qk(ans+1ll*ddp[(1<<n)-1][i]*res[i]%mo);
cout<<ans<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 3ms
memory: 5116kb
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: 3ms
memory: 5136kb
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: 3ms
memory: 5176kb
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: 3ms
memory: 5156kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Accepted
time: 3ms
memory: 5184kb
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: 5180kb
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: 5292kb
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: 3ms
memory: 5180kb
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: 0ms
memory: 5124kb
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: 5228kb
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: 5236kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 0
Accepted
time: 3ms
memory: 5292kb
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: 5256kb
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: 4ms
memory: 5224kb
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: 5124kb
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: 4ms
memory: 5280kb
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:
223286308
result:
wrong answer 1st numbers differ - expected: '5392583', found: '223286308'
Subtask #3:
score: 10
Accepted
Test #47:
score: 10
Accepted
time: 31ms
memory: 7372kb
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: 1ms
memory: 5424kb
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: 1ms
memory: 5188kb
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: 4ms
memory: 5368kb
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:
100%
Accepted
Dependency #2:
0%