QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686946 | #1839. Joke | Andy_Lin | WA | 7ms | 11960kb | C++17 | 963b | 2024-10-29 16:26:57 | 2024-10-29 16:26:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 101
#define mod 998244353
int n,m,pos[N],val[N];
bool flag[N];
int f[N][N][N],g[N][N][N];
int ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",pos+i);
for(int i=1;i<=n;++i)scanf("%d",val+pos[i]),flag[val[pos[i]]]=1;
for(int i=1;i<=n;++i)if(!flag[i])++m;
f[0][0][0]=1;
for(int i=0;i<=n;++i)g[0][0][i]=1;
for(int i=1;i<=n;++i){
for(int j=0;j<=m;++j){
for(int k=0;k<=n;++k){
f[i][j][k]=f[i-1][j][k];
if(k&&val[i]==k){
f[i][j][k]=(f[i][j][k]+g[i-1][j][k-1])%mod;
}
if(!val[i]&&!flag[k]&&j)f[i][j][k]=(f[i][j][k]+g[i-1][j-1][k-1])%mod;
g[i][j][k]=f[i][j][k];
g[i][j][k]=(g[i][j][k]+g[i][j][k-1])%mod;
}
}
}
for(int i=0;i<=m;++i){
int now=g[n][i][n];
for(int j=1;j<=m-i;++j)now=1ll*now*j%mod;
ans=(ans+now)%mod;
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8004kb
input:
2 1 2 2 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
4 4 3 2 1 4 3 2 1
output:
16
result:
ok 1 number(s): "16"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5992kb
input:
5 1 2 3 4 5 0 0 0 0 0
output:
1546
result:
ok 1 number(s): "1546"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
6 1 6 2 5 3 4 0 1 0 2 0 3
output:
52
result:
ok 1 number(s): "52"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
10 8 2 10 3 4 6 1 7 9 5 0 0 0 0 0 0 0 0 0 0
output:
234662231
result:
ok 1 number(s): "234662231"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6080kb
input:
10 5 8 4 9 6 1 2 7 3 10 8 3 0 5 0 9 0 0 6 0
output:
5294
result:
ok 1 number(s): "5294"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5952kb
input:
10 4 2 6 9 5 3 8 1 10 7 0 9 8 0 7 3 4 2 1 10
output:
166
result:
ok 1 number(s): "166"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5860kb
input:
10 8 2 7 1 5 9 3 4 10 6 7 0 2 9 5 1 8 4 3 6
output:
26
result:
ok 1 number(s): "26"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
10 10 1 6 7 9 8 4 3 5 2 2 5 1 3 9 10 4 8 6 7
output:
47
result:
ok 1 number(s): "47"
Test #10:
score: 0
Accepted
time: 2ms
memory: 8980kb
input:
50 41 15 17 1 5 31 7 38 30 39 43 35 2 26 20 42 48 25 19 32 50 4 8 10 44 12 9 18 13 36 28 6 27 23 40 24 3 14 29 11 49 47 45 46 34 21 37 16 22 33 0 0 0 0 0 0 0 0 0 33 34 0 0 0 0 0 0 0 0 0 0 2 0 0 0 20 0 0 28 0 0 0 9 0 0 0 48 0 0 0 50 0 0 0 0 5 0 0 32 0
output:
976189245
result:
ok 1 number(s): "976189245"
Test #11:
score: 0
Accepted
time: 0ms
memory: 8792kb
input:
50 36 35 13 14 45 44 22 10 30 23 15 17 6 42 8 49 21 46 5 32 25 34 38 4 48 50 28 3 9 24 43 47 20 2 40 37 29 41 26 7 39 33 31 19 27 16 11 12 1 18 0 0 0 19 20 42 0 18 9 0 27 0 38 0 0 45 0 33 0 0 0 0 0 7 0 0 37 41 0 2 0 1 0 0 5 13 8 0 0 0 0 0 0 15 17 0 12 0 0 0
output:
861991745
result:
ok 1 number(s): "861991745"
Test #12:
score: 0
Accepted
time: 1ms
memory: 8512kb
input:
50 24 4 17 27 45 5 8 33 7 23 19 42 11 2 39 38 48 37 32 29 18 47 6 36 25 15 31 50 12 3 44 28 30 41 40 16 14 21 46 22 34 9 43 26 49 35 10 1 20 13 15 0 0 19 0 0 0 0 0 5 3 0 31 0 25 26 41 7 9 0 22 0 11 49 24 0 43 13 14 35 16 0 27 0 0 0 47 0 0 18 20 23 33 42 36 8 0 30 44 0
output:
231982952
result:
ok 1 number(s): "231982952"
Test #13:
score: 0
Accepted
time: 1ms
memory: 8408kb
input:
50 37 9 29 2 13 35 7 16 12 42 34 47 14 46 27 6 21 32 15 49 20 10 31 48 18 4 23 40 25 30 50 41 24 26 11 5 33 36 8 22 39 3 17 43 44 1 45 28 19 38 50 33 0 0 14 10 13 15 16 0 35 12 5 9 34 6 0 38 21 22 45 0 0 28 31 36 0 43 29 37 7 1 20 44 11 4 40 2 0 17 27 39 0 3 30 0 24 26 25 18
output:
31263262
result:
ok 1 number(s): "31263262"
Test #14:
score: 0
Accepted
time: 1ms
memory: 8200kb
input:
50 24 47 6 19 1 25 42 38 18 2 7 3 13 27 23 48 28 36 45 39 37 29 16 12 15 10 8 46 33 34 43 14 50 9 31 32 44 20 26 4 40 22 17 49 35 41 11 21 5 30 7 47 5 19 31 9 48 14 32 11 12 13 33 36 42 29 26 24 39 46 28 15 50 8 30 22 35 3 4 43 10 38 41 6 21 20 2 27 16 37 23 17 45 34 49 40 25 18 44 1
output:
78388
result:
ok 1 number(s): "78388"
Test #15:
score: -100
Wrong Answer
time: 7ms
memory: 11960kb
input:
100 11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98 0 0 ...
output:
46291793
result:
wrong answer 1st numbers differ - expected: '452312947', found: '46291793'