QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140106 | #5411. 杏仁 | 1kri# | 0 | 793ms | 229668kb | C++14 | 1.6kb | 2023-08-15 08:46:06 | 2024-07-04 02:37:26 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#define mod 998244353
#define ll long long
using namespace std;
void inc(int &x,int y){
x+=y;
if (x>=mod)x-=mod;
return;
}
int n,m,s,t,c[22][22];
int pow_2[10005];
int f[1048576][22][2];
int dfs(int S,int p,int o){
if (f[S][p][o]!=-1)return f[S][p][o];
ll ans=0;
if (o==1)ans=c[p][t];
int _o=1;
for (int i=0;i<n;i++)
if (!(S&(1<<i))){
if (i==s||i==t)continue;
ans+=1ll*c[p][i]*dfs(S|(1<<i),i,o|(_o));
if (o==1)ans+=1ll*c[p][t]*c[s][i]*dfs(S|(1<<i),i,_o);
}
else _o=0;
ans%=mod;
return f[S][p][o]=ans;
}
int g[1048576][22][2];
int val[22];
int q,x;
int main(){
cin>>n>>m;
cin>>s>>t,s--,t--;
for (int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
u--,v--;
c[u][v]++;
}
pow_2[0]=1;
for (int i=1;i<=m;i++)pow_2[i]=pow_2[i-1]*2%mod;
memset(f,-1,sizeof(f));
g[0][s][1]=1;
for (int S=0;S<(1<<n);S++){
if ((S&(1<<s))||(S&(1<<t)))continue;
for (int p=0;p<n;p++)
for (int o=0;o<2;o++){
int v=g[S][p][o],_o=1;
if (v==0)continue;
for (int i=0;i<n;i++){
if (!(S&(1<<i))){
if (i==s||i==t)continue;
int _v=1ll*c[p][i]*v%mod;
inc(g[S|(1<<i)][i][o|_o],_v);
if (p==s)inc(val[i],1ll*_v*dfs(S|(1<<i),i,o|_o)%mod);
if (o==1){
int _v=1ll*c[p][t]*c[s][i]*v%mod;
inc(g[S|(1<<i)][i][_o],_v);
inc(val[i],1ll*_v*dfs(S|(1<<i),i,_o)%mod);
if (p==s)inc(val[t],1ll*_v*dfs(S|(1<<i),i,_o)%mod);
}
}
else _o=0;
}
}
}
inc(val[t],c[s][t]);
cin>>q;
while(q--){
cin>>x;
x--;
cout<<val[x]<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 15ms
memory: 185376kb
input:
5 10 1 5 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 4 2 3 4 5
output:
20 14 10 15
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 15ms
memory: 184760kb
input:
2 0 1 2 0
output:
result:
ok 0 lines
Test #3:
score: -10
Wrong Answer
time: 0ms
memory: 185808kb
input:
4 20 1 4 1 4 2 4 1 4 2 4 1 1 3 4 3 1 2 4 1 3 1 3 3 2 2 3 4 1 3 1 2 3 1 4 3 2 4 4 3 1 1 4 4 2 4 3 2
output:
0 60 70 0
result:
wrong answer 2nd lines differ - expected: '225', found: '60'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Runtime Error
Test #15:
score: 10
Accepted
time: 147ms
memory: 197340kb
input:
18 324 9 8 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 ...
output:
256104819 256104819 238677015 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819 256104819
result:
ok 18 lines
Test #16:
score: 0
Accepted
time: 793ms
memory: 229668kb
input:
20 400 13 20 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 4 1 4 2 4 3 4 ...
output:
681008066 681008066 681008066 681008066 681008066 681008066 681008066 681008066 205106617 681008066 681008066 681008066 681008066 681008066 681008066 681008066 681008066 681008066 681008066 681008066
result:
ok 20 lines
Test #17:
score: -10
Runtime Error
input:
21 441 16 17 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Runtime Error
Test #23:
score: 0
Runtime Error
input:
22 9384 9 19 9 19 3 18 9 17 9 19 15 19 14 17 9 18 9 14 9 18 9 19 16 19 3 10 9 2 2 1 21 10 1 19 4 3 19 3 9 16 18 21 9 22 9 8 13 8 2 7 4 16 9 12 15 12 3 19 19 10 16 10 14 19 19 16 14 19 1 4 11 5 5 13 3 19 9 6 17 22 4 18 1 13 2 18 19 16 18 17 12 22 21 3 5 11 18 7 14 19 8 19 9 20 16 19 22 19 18 12 9 19 ...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
0%