QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#88635 | #5827. 异或图 | ooooxxxx | 20 | 4ms | 5544kb | C++14 | 3.9kb | 2023-03-16 20:25:10 | 2023-03-16 20:25:12 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int mod=998244353;
#define int long long
inline int qpow(int a,int b){
int ret=1;
while(b){
if(b&1) ret=ret*a%mod;
a=a*a%mod;b>>=1;
}return ret;
}
const int N=15;
int n,m,c;
int a[N],A[N];
// vector<int>dp[(1<<15)+10];
int dp[(1<<13)+1][(1<<13)+1];
int ban[(1<<15)+10];
#define rep(i,l,r) for(int i=l;i<=r;i++)
inline int solve(int s){
vector<int>b;
int ans=0;
int sum=0;
for(int i=0;i<n;i++)
if((s>>i)&1) b.push_back(a[i]),sum^=a[i];
if(sum==c) ans++;
for(int i=60;i>=0;i--){
int sum=0;
for(int x:b)sum^=((x>>(i+1)));
if(sum==(c>>(i+1))){
static int f[2][2],g[2][2];
memset(f,0,sizeof(f));
f[0][0]=1;
for(int x:b){
if((x>>i)&1){
int s0=(1ll<<i)%mod;
int s1=(x&((1ll<<i)-1))+1;s1%=mod;
g[0][0]=f[0][1]*s1;
g[0][1]=f[0][0]*s1;
g[1][0]=f[1][0]*s0+f[1][1]*s1+f[0][0];
g[1][1]=f[1][1]*s0+f[1][0]*s1+f[0][1];
rep(u,0,1)rep(v,0,1) f[u][v]=g[u][v]%mod;
}else{
int cur=(x&((1ll<<i)-1))+1;cur%=mod;
rep(u,0,1)rep(v,0,1) f[u][v]=f[u][v]*cur%mod;
}
}
ans+=f[1][(c>>i)&1];
ans%=mod;
}
}return ans;
}
inline void dec(int &x){
x-=(x>=mod?mod:0);
}
int g[(1<<N)+10],h[(1<<N)+10];
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m>>c;
for(int i=0;i<n;i++) cin>>a[i];
static int p[N],q[N];
for(int i=0;i<n;i++) p[i]=i;
sort(p,p+n,[&](int u,int v){
return a[u]<a[v];
});
for(int i=0;i<n;i++) q[p[i]]=i;
sort(a,a+n);
for(int i=1;i<=m;i++){
int x,y;cin>>x>>y;x--,y--;
ban[(1<<q[x])+(1<<q[y])]=1;
}
for(int mid=1;mid<(1<<n);mid<<=1){
for(int j=0;j<(1<<n);j+=(mid<<1))
for(int k=0;k<mid;k++)ban[j+k+mid]+=ban[j+k];
}
g[0]=1;
for(int s=1;s<(1<<n);s++){
int i=__builtin_ctz(s);
int res=0;
if(ban[s]) res=0;
else res=1;
// if(s==3)
// cerr<<"?? "<<ban[3]<<" "<<res<<endl;
for(int z=s;z;z=(z-1)&s){
if(z==s) continue;
if(__builtin_ctz(z)==i){
if(!ban[s^z]) res-=g[z],res%=mod;
// cerr<<"? "<<i<<" "<<s<<" "<<z<<" "<<g[z]<<" "<<res<<endl;
}
}g[s]=res;
}
dp[0][0]=1;
// cerr<<"? "<<ban[7]<<" "<<ban[1]<<" "<<ban[2]<<endl;exit(0);
for(int i=0;i<n;i++){
for(int s=0;s<(1<<n);s++){
if((s&((1<<i)-1))==(1<<i)-1&&!((s>>i)&1)){
int U=((1<<n)-1)^(s+(1<<i));
int S=((1<<n)-1)^s;
for(int u=U;;u=(u-1)&U){
int c=S^u;
if(__builtin_parity(c)){
for(int z=s;;z=(z-1)&s){
// cerr<<"? "<<s<<" "<<z<<" "<<dp[s][z]<<" "<<c<<" "<<k<<"|"<<dp[7][1]<<endl;
(dp[s|c][z|(1<<i)]+=g[c]*dp[s][z])%=mod;
if(!z) break;
}
}else{
for(int z=s;;z=(z-1)&s){
(dp[s|c][z]+=g[c]*dp[s][z]%mod*(a[i]+1))%=mod;
if(!z) break;
}
}
if(!u) break;
}
}
}
}
int ans=0;
int s=(1<<n)-1;
// cerr<<"======\n";
for(int u=0;u<(1<<n);u++){
// cerr<<"? "<<u<<" "<<dp[s][u]<<" "<<solve(u)<<endl;
(ans+=dp[s][u]*solve(u))%=mod;
}
cout<<ans;
}
詳細信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 1ms
memory: 5408kb
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: 5544kb
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: 3388kb
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: 1ms
memory: 3392kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Accepted
time: 2ms
memory: 5412kb
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: 3420kb
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: 3452kb
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: 3456kb
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: 5396kb
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: 3424kb
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: 0ms
memory: 3508kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3516kb
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: 3560kb
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: 2ms
memory: 3560kb
input:
5 0 12 9 8 14 11 2
output:
3006
result:
ok 1 number(s): "3006"
Test #15:
score: 0
Accepted
time: 2ms
memory: 3380kb
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: 4968kb
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:
-711950580
result:
wrong answer 1st numbers differ - expected: '5392583', found: '-711950580'
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:
100%
Accepted
Dependency #2:
0%