QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140108 | #5411. 杏仁 | 1kri# | 20 | 155ms | 191392kb | C++14 | 1.8kb | 2023-08-15 08:51:14 | 2024-07-04 01:42:46 |
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 id[4200005];
int f[1048576][22][2];
int dfs(int S,int p,int o){
if (f[id[S]][p][o]!=-1)return f[id[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[id[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]++;
}
for (int i=0;i<(1<<n);i++){
for (int j=n-1;j>=0;j--)
if (j!=s&&j!=t)id[i]=(id[i]<<1)+((i>>j)&1);
}
pow_2[0]=1;
for (int i=1;i<=m;i++)pow_2[i]=pow_2[i-1]*2%mod;
c[s][t]=pow_2[c[s][t]]-1;
memset(f,-1,sizeof(f));
g[id[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[id[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[id[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[id[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;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 3ms
memory: 184096kb
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: 8ms
memory: 185916kb
input:
2 0 1 2 0
output:
result:
ok 0 lines
Test #3:
score: 0
Accepted
time: 7ms
memory: 184276kb
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 225 224 0
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 8ms
memory: 185328kb
input:
5 20 1 5 1 5 1 2 4 2 5 3 1 1 1 4 4 5 5 1 1 3 2 5 2 4 3 1 5 2 4 3 4 3 3 4 5 1 4 2 4 5 3 4 5 3 4 2 5 5
output:
24 12 18 22 22
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 4ms
memory: 185904kb
input:
6 20 4 5 4 5 4 1 5 3 2 6 3 5 3 5 5 3 1 4 2 5 4 5 3 5 1 3 3 5 4 2 4 4 3 5 6 5 1 6 5 6 4 4 6 2 3 5 6 1 3
output:
52 0 60 0 68 0
result:
ok 6 lines
Test #6:
score: 0
Accepted
time: 3ms
memory: 184296kb
input:
11 20 3 1 3 1 3 7 9 1 4 9 7 4 9 11 6 11 9 5 3 5 3 7 8 9 1 7 10 1 6 11 11 5 3 7 8 10 7 1 9 7 11 8 10 2 10 7 8 11 1 6 9 5 1
output:
0 0 18 0 0 10 0 0 0 10
result:
ok 10 lines
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 10
Accepted
time: 4ms
memory: 184788kb
input:
11 9728 6 10 6 10 9 10 5 10 6 4 4 10 1 6 8 10 3 8 1 10 9 7 5 3 6 4 6 5 11 6 9 6 6 6 3 10 2 4 2 11 6 10 6 2 6 5 10 6 2 10 11 2 9 10 1 10 9 10 7 8 3 1 8 3 3 7 9 11 2 9 6 4 10 11 8 4 2 10 11 10 6 3 6 10 6 11 1 11 6 9 7 11 8 3 9 7 2 1 11 2 6 2 4 1 3 10 6 6 6 11 3 2 10 10 7 10 7 10 6 6 6 8 4 3 4 10 4 2 1...
output:
18074853 107213401 341119309 102827400 474349010 797006791 628391650 336670841 867783896 401391226 341119309
result:
ok 11 lines
Test #8:
score: 0
Accepted
time: 8ms
memory: 185008kb
input:
11 9613 4 1 4 1 8 9 11 1 7 8 4 10 2 1 6 11 4 2 11 9 5 7 11 6 2 6 11 2 3 9 3 9 1 1 6 3 1 6 3 1 2 1 10 5 4 9 4 2 10 1 7 8 6 8 3 1 9 11 4 9 5 1 1 7 11 3 10 8 8 11 2 9 3 1 7 1 8 1 7 8 4 4 4 7 3 7 1 1 6 1 4 6 5 1 8 7 4 4 1 6 4 9 4 11 5 3 10 7 7 2 6 5 4 9 4 9 8 7 5 1 4 1 1 1 4 6 11 1 3 7 8 11 6 1 1 10 8 4...
output:
182705163 786446186 459586140 963615780 865915814 315502014 910204714 865915814 514046009 72155443 281775231
result:
ok 11 lines
Test #9:
score: 0
Accepted
time: 14ms
memory: 184572kb
input:
11 9669 10 6 10 6 10 7 10 9 2 6 4 6 10 6 10 6 11 1 3 9 4 10 1 8 9 11 3 9 3 5 1 6 11 7 4 6 2 11 3 6 6 7 3 5 8 11 6 11 3 10 10 9 8 2 2 8 11 3 10 7 3 6 10 9 3 6 5 7 11 8 8 6 7 11 4 2 4 3 3 5 6 1 10 1 11 4 10 11 3 8 6 8 10 7 3 2 1 6 3 9 3 2 6 3 9 2 10 2 5 8 7 6 11 3 10 3 8 4 2 3 10 5 10 8 9 4 4 3 5 6 10...
output:
149327198 149327198 621010244 313847170 72070176 640755787 768354631 327768688 860362353 839515336 716753550
result:
ok 11 lines
Test #10:
score: 0
Accepted
time: 12ms
memory: 185028kb
input:
11 9989 8 4 8 4 8 10 6 3 5 4 3 10 8 5 1 6 2 4 7 4 3 2 5 8 11 4 11 4 8 5 9 1 5 8 11 3 8 4 8 4 4 3 3 4 8 1 2 3 11 9 3 6 2 11 8 6 4 10 5 4 3 5 5 4 10 3 5 11 9 6 8 4 1 10 2 7 11 3 8 11 2 3 2 11 7 4 2 6 8 1 8 4 8 11 2 9 9 1 8 9 5 4 8 8 3 4 9 11 8 5 8 2 6 2 9 4 10 1 8 4 10 2 5 8 8 4 8 4 10 6 8 4 2 1 10 4 ...
output:
925008018 925008018 417424703 233031232 592456114 905513142 507449485 987584281 67045289 93256542 679477325
result:
ok 11 lines
Subtask #3:
score: 0
Checker Judgement Failed
Dependency #2:
100%
Accepted
Test #11:
score: 15
Accepted
time: 155ms
memory: 191392kb
input:
17 9734 12 7 12 7 12 13 12 17 12 13 5 6 9 15 12 4 12 17 8 5 7 3 12 15 7 11 5 9 6 3 2 1 5 3 12 14 8 14 13 1 12 17 8 5 1 7 10 7 1 3 17 4 12 13 4 9 12 11 12 15 12 2 10 7 2 7 15 17 15 16 11 2 2 9 9 13 12 13 10 16 12 4 9 7 6 8 10 3 12 9 14 1 4 11 12 5 14 7 16 5 13 7 1 7 5 9 12 1 3 16 10 1 5 11 3 6 9 1 12...
output:
495528391 190001284 700736504 375686904 65816767 495528391 159308841 716930343 767343668 644562391 605875454 655781543 517152891 728480649 862738224 186485114 473518401
result:
ok 17 lines
Test #12:
score: 0
Accepted
time: 150ms
memory: 191212kb
input:
17 9672 15 6 15 6 4 12 15 3 6 4 8 6 15 1 1 6 15 3 6 3 9 10 15 6 8 12 1 5 13 6 1 10 13 1 3 6 17 10 15 6 14 6 15 15 15 12 6 17 7 17 15 10 10 14 10 1 9 16 9 6 9 3 10 3 15 12 10 15 11 17 8 6 15 6 14 16 13 7 15 5 1 6 6 8 5 3 13 6 4 16 12 6 15 10 2 13 9 6 10 12 11 6 4 16 15 17 8 6 15 13 12 6 2 6 16 6 14 8...
output:
279235714 30374151 24538748 679469233 229435792 155945081 450016612 514325705 338303999 985948696 888015758 183228636 644327192 941925587 178117228 380944360
result:
ok 16 lines
Test #13:
score: -15
Checker Judgement Failed
input:
17 9211 2 5 2 5 9 2 12 5 7 3 17 5 8 10 4 5 5 7 2 6 1 6 13 15 2 3 4 2 16 5 10 5 17 5 10 5 12 5 2 8 2 13 2 8 16 5 16 17 13 6 6 5 13 9 2 13 9 5 16 4 1 3 9 8 5 8 13 8 13 8 17 9 12 8 2 7 8 12 3 5 2 2 2 6 5 10 17 16 15 8 6 5 7 2 2 5 5 13 2 11 3 12 11 17 2 1 3 1 5 5 16 5 14 1 14 3 2 5 2 11 1 2 11 17 8 17 1...
output:
908804301 908804301 307393040 186849899 781252717 119888384 204862051 534656059 895145247 661847250 924518557 467036885 58336416 491807201 908827619 558794051 946875930
result:
Subtask #4:
score: 0
Runtime Error
Test #15:
score: 0
Runtime Error
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:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Time Limit Exceeded
Test #23:
score: 0
Time Limit Exceeded
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:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%