QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140105 | #5411. 杏仁 | 1kri# | 0 | 0ms | 0kb | C++14 | 1.6kb | 2023-08-15 08:44:52 | 2024-07-04 01:42:41 |
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[4200005][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[4200005][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;
}
详细
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 0
Memory Limit Exceeded
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:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Memory Limit Exceeded
Test #15:
score: 0
Memory Limit Exceeded
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:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Memory Limit Exceeded
Test #23:
score: 0
Memory 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:
596857653
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
0%