QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355576 | #5827. 异或图 | zjy0001 | 0 | 1ms | 3864kb | C++14 | 2.3kb | 2024-03-16 20:59:15 | 2024-03-16 20:59:16 |
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long
using namespace std;
const int N=15,M=1<<N,P=998244353;
int n,m,ans;LL C,a[N];
int id[N],pos[N],F[M],G[M],f[M],g[M];
inline int calc(const vector<LL>&a){
const int n=a.size();
LL v=0,z=0;for(auto&i:a)v^=i;z+=(!v);
for(int i=60;~i&&!(v>>(i+1));--i){
array<array<int,2>,2>f{1,0,0,0};
for(auto&k:a){
array<array<int,2>,2>g{0,0,0,0};
for(auto x:{0,1})for(auto y:{0,1})if(f[x][y]){
const int t=((a[k]&((1ll<<i)-1))+1)%P;
if(k>>i&1)
g[x][1]=(g[x][1]+(y?(1ll<<i)%P:1ll)*f[x][y])%P,
g[!x][y]=(g[!x][y]+1ll*f[x][y]*t)%P;
else g[x][y]=(g[x][y]+1ll*f[x][y]*t)%P;
}
f=g;
}
z+=f[0][1];
}
return z%P;
}
inline int solve(vector<LL>a){
int t=calc(a);if(a[0])--a[0],t-=calc(a);return t;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m>>C;
fill(G,G+(1<<n),1);
for(int i=0;i<n;++i)cin>>a[i],pos[i]=i;
sort(pos,pos+n,[&](const int&x,const int&y){return a[x]<a[y];}),sort(a,a+n);
for(int i=0;i<n;++i)id[pos[i]]=i;
for(int i=0;i<m;++i){
int u,v;cin>>u>>v,u=id[u-1],v=id[v-1];
for(int S=0;S<(1<<n);++S)if((S>>u&1)&&(S>>v&1))G[S]=0;
}
for(int S=0;S<(1<<n);++S){
F[S]=G[S];
for(int T=(S-1)&S;T>(T^S);T=(T-1)&S)
if(G[S^T])(F[S]-=F[T])<0&&(F[S]+=P);
}
f[0]=1;
for(int i=0;i<n;++i){
fill(g,g+(1<<n),0);
for(int S=0;S<(1<<n);++S)if(f[S])
if(S>>i&1)(g[1<<i^S]+=f[S])>=P&&(g[1<<i^S]-=P);
else for(int R=(S^((1<<n)-1))&((-1)<<(i+1)),T=R;;T=(T-1)&R){
const int U=1<<i|T;
if(__builtin_parity(U))g[S|U]=(g[S|U]+1ll*F[U]*f[S])%P;
else g[S|T]=(g[S|T]+(a[i]+1)%P*F[U]%P*f[S])%P;
if(!T)break;
}
swap(f,g);
}
for(int S=0;S<(1<<n);++S)if(f[S]){
vector<LL>b({C});for(int i=0;i<n;++i)if(S>>i&1)b.emplace_back(a[i]);
ans=(ans+1ll*f[S]*solve(b))%P;
}
return cout<<(ans<0?ans+P:ans),0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3864kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
998244311
result:
wrong answer 1st numbers differ - expected: '44', found: '998244311'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #47:
score: 0
Runtime Error
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%