QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90595 | #5827. 异或图 | yyyyxh | 20 | 1374ms | 104956kb | C++17 | 2.2kb | 2023-03-23 21:29:39 | 2023-03-23 21:29:42 |
Judging History
answer
#include <cstdio>
#include <unordered_map>
using namespace std;
template<typename T>
T read(){
char c=getchar();T x=0;
while(c<48||c>57) c=getchar();
do x=(x<<1)+(x<<3)+(c^48),c=getchar();
while(c>=48&&c<=57);
return x;
}
const int N=33,S=1<<15,LG=63,P=998244353;
typedef long long ll;
int n,m,rk;ll c;
ll a[N],lis[N];
bool ban[S];
int coe[S],pos[S];
void inc(int &x,int v){if((x+=v)>=P) x-=P;}
void dec(int &x,int v){if((x-=v)<0) x+=P;}
unordered_map<int,int> f[S];
int suf[N][2];
bool sta[LG];
int main(){
n=read<int>();m=read<int>();c=read<ll>();
for(int i=0;i<n;++i) a[i]=read<ll>();
for(int i=0;i<m;++i){
int u=read<int>()-1,v=read<int>()-1;
ban[(1<<u)|(1<<v)]=1;
}
for(int i=1;i<(1<<n);i<<=1)
for(int j=0;j<(1<<n);j+=(i<<1))
for(int k=j;k<(j|i);++k) ban[k|i]|=ban[k];
for(int s=1;s<(1<<n);++s){
int lb=__builtin_ctz(s);
int _s=s^(1<<lb);
pos[s]=lb;
if(_s&&a[pos[_s]]<a[lb]) pos[s]=pos[_s];
coe[s]=!ban[s];
for(int _t=_s;;_t=(_t-1)&_s){
int t=_t|(1<<lb);
if(t!=s&&!ban[s^t]) dec(coe[s],coe[t]);
if(!_t) break;
}
}
f[0][0]=1;
for(int s=1;s<(1<<n);++s){
int lb=__builtin_ctz(s);
int _s=s^(1<<lb);
for(int _t=_s;;_t=(_t-1)&_s){
int t=_t|(1<<lb);
for(auto [x,val]:f[s^t])
if(__builtin_parity(t)) inc(f[s][x|(1<<pos[t])],(ll)coe[t]*val%P);
else inc(f[s][x],(a[pos[t]]+1)%P*val%P*coe[t]%P);
if(!_t) break;
}
}
int res=0;
for(auto [s,val]:f[(1<<n)-1]){
rk=0;
for(int i=0;i<n;++i)
if(s>>i&1) lis[rk++]=a[i];
int ans=0;
for(int t=59;~t;--t){
suf[rk][0]=1;suf[rk][1]=0;
for(int i=rk-1;~i;--i){
sta[i]=lis[i]>>t&1;
if(sta[i]){
lis[i]^=(1ll<<t);
suf[i][0]=((1ll<<t)%P*suf[i+1][0]+(lis[i]+1)%P*suf[i+1][1])%P;
suf[i][1]=((1ll<<t)%P*suf[i+1][1]+(lis[i]+1)%P*suf[i+1][0])%P;
}
else{
suf[i][0]=(lis[i]+1)%P*suf[i+1][0]%P;
suf[i][1]=(lis[i]+1)%P*suf[i+1][1]%P;
}
}
int par=(c>>t&1),cur=1;
for(int i=0;i<rk;++i){
if(sta[i]){
ans=(ans+(ll)cur*suf[i+1][par])%P;
par^=1;
}
cur=(ll)cur*(lis[i]+1)%P;
}
if(par) break;
if(!t) ++ans;
}
res=(res+(ll)ans*val)%P;
}
printf("%d\n",res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 4876kb
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: 0ms
memory: 4776kb
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: 4752kb
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: 4692kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Accepted
time: 3ms
memory: 4692kb
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: 0ms
memory: 4704kb
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: 3ms
memory: 4660kb
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: 4720kb
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: 4624kb
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: 3ms
memory: 4752kb
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: 3ms
memory: 4776kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 0
Accepted
time: 3ms
memory: 4716kb
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: 3ms
memory: 4744kb
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: 3ms
memory: 4836kb
input:
5 0 12 9 8 14 11 2
output:
3006
result:
ok 1 number(s): "3006"
Test #15:
score: 0
Accepted
time: 3ms
memory: 4692kb
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: 5ms
memory: 5340kb
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:
-550493602
result:
wrong answer 1st numbers differ - expected: '5392583', found: '-550493602'
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 1374ms
memory: 104956kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
-349389813
result:
wrong answer 1st numbers differ - expected: '231790380', found: '-349389813'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%