QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83387 | #5411. 杏仁 | zhouhuanyi | 10 | 3749ms | 269684kb | C++23 | 2.6kb | 2023-03-01 17:20:00 | 2023-03-01 17:20:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 20
#define mod 998244353
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int lowbit(int x)
{
return x&(-x);
}
int MD2(int x)
{
return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int n,m,q,s,t,ans,c1[N+1],c2[N+1],sz[1<<N],inv[N+1],E[N+1][N+1],dp[1<<N][N+1],F[N+1][1<<N],G[N+1][1<<N],delta[1<<N];
int get(int x)
{
return x-(x>s)-(x>t);
}
void FWT(int *s,int type)
{
if (type==1)
{
for (int i=1;i<=n;++i)
for (int j=0;j<(1<<n);++j)
if (j&(1<<(i-1)))
Adder(s[j],s[j^(1<<(i-1))]);
}
else
{
for (int i=1;i<=n;++i)
for (int j=0;j<(1<<n);++j)
if (j&(1<<(i-1)))
Adder2(s[j],-s[j^(1<<(i-1))]);
}
return;
}
int main()
{
int x,y,cnt=0;
n=read()-2,m=read(),s=read(),t=read(),inv[1]=1;
for (int i=2;i<=n;++i) inv[i]=MD2(-1ll*(mod/i)*inv[mod%i]%mod);
for (int i=1;i<(1<<n);++i) sz[i]=sz[i-lowbit(i)]+1;
for (int i=1;i<=m;++i)
{
x=read(),y=read();
if (x!=y)
{
if (x==s&&y==t) cnt++;
else if (x==s) Adder(c1[get(y)],1);
else if (y==t) Adder(c2[get(x)],1);
else if (x!=t&&y!=s) Adder(E[get(x)][get(y)],1);
}
}
for (int i=1;i<=n;++i) dp[1<<(i-1)][i]=c2[i];
for (int i=0;i<(1<<n);++i)
for (int j=1;j<=n;++j)
if (i&(1<<(j-1)))
for (int k=1;k<=n;++k)
if ((!(i&(1<<(k-1)))))
Adder(dp[i|(1<<(k-1))][k],1ll*dp[i][j]*E[k][j]%mod);
for (int i=0;i<(1<<n);++i)
for (int j=1;j<=n;++j)
if (i&(1<<(j-1)))
Adder(F[sz[i]][i],1ll*dp[i][j]*c1[j]%mod);
for (int i=0;i<=n;++i) FWT(F[i],1);
for (int i=0;i<(1<<n);++i)
{
G[0][i]=1;
for (int j=1;j<=n;++j)
{
for (int k=1;k<=j;++k) Adder(G[j][i],1ll*G[j-k][i]*F[k][i]%mod*k%mod);
G[j][i]=1ll*G[j][i]*inv[j]%mod;
}
}
for (int i=0;i<=n;++i) FWT(G[i],-1);
for (int i=0;i<(1<<n);++i) delta[i]=G[sz[i]][i];
for (int i=1;i<=n;++i)
for (int j=0;j<(1<<n);++j)
if (j&(1<<(i-1)))
Adder(delta[j],delta[j^(1<<(i-1))]);
q=read();
while (q--)
{
x=read(),ans=0;
if (x==t) Adder(ans,1ll*delta[(1<<n)-1]*cnt%mod);
else
{
x=get(x);
for (int i=0;i<(1<<n);++i)
if (i&(1<<(x-1)))
Adder(ans,1ll*dp[i][x]*c1[x]%mod*delta[((1<<n)-1)^i]%mod*(cnt+1)%mod);
}
printf("%d\n",ans);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 1ms
memory: 9616kb
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: 1ms
memory: 7576kb
input:
2 0 1 2 0
output:
result:
ok 0 lines
Test #3:
score: -10
Wrong Answer
time: 0ms
memory: 9528kb
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: 10
Accepted
Test #15:
score: 10
Accepted
time: 115ms
memory: 22136kb
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: 583ms
memory: 68588kb
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: 0
Accepted
time: 1280ms
memory: 136416kb
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:
689426186 689426186 689426186 689426186 689426186 689426186 689426186 689426186 689426186 689426186 689426186 689426186 689426186 319626977 689426186 689426186 689426186 689426186 689426186 689426186 689426186
result:
ok 21 lines
Test #18:
score: 0
Accepted
time: 2836ms
memory: 269684kb
input:
22 484 10 1 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 1 22 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 2 22 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 ...
output:
761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899 761174899
result:
ok 16 lines
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 3749ms
memory: 269668kb
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:
wrong answer 1st lines differ - expected: '667211711', found: '596857653'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%