QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291107 | #3242. 骰子旅行 | MoRanSky | AC ✓ | 129ms | 8212kb | C++23 | 1.7kb | 2023-12-26 04:53:10 | 2023-12-26 04:53:10 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int P = 998244353, N = 105;
int n, s0, t, f[N][N], g[N][N], m[N], inv[N], I[N], h[N][N][N];
int ans;
void inline add(int &x, int y) {
x += y;
if (x >= P) x -= P;
}
int main() {
//freopen("3.in", "r", stdin);
inv[1] = 1;
read(n), read(s0), read(t);
for (int i = 2; i <= n; i++) {
inv[i] = (P - (LL)P / i) * inv[P % i] % P;
}
for (int i = 1; i <= n; i++) {
read(m[i]);
for (int j = 1; j <= m[i]; j++) {
int x; read(x);
g[i][x] = 1;
}
I[i] = inv[m[i]];
}
f[0][s0] = 1;
for (int i = 0; i < t; i++) {
for (int u = 1; u <= n; u++) {
for (int v = 1; v <= n; v++) {
if (g[u][v]) {
int w = 1ll * f[i][u] * I[u] % P;
add(f[i + 1][v], w);
if (v != u) add(h[i + 1][v][u], 1ll * w * v % P);
else add(ans, 1ll * w * v % P);
}
}
for (int b = 1; b <= n; b++) {
if (!h[i][u][b]) continue;
for (int v = 1; v <= n; v++) {
if (!g[u][v]) continue;
if (v == b) {
add(ans, 1ll * h[i][u][b] * I[u] % P);
} else {
add(h[i + 1][v][b], 1ll * h[i][u][b] * I[u] % P);
}
}
}
}
}
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 129ms
memory: 8100kb
input:
100 30 100 51 8 80 45 28 2 36 19 49 74 41 24 65 3 87 7 88 10 77 91 55 92 59 69 98 84 73 83 31 40 35 23 94 62 71 46 86 12 82 5 81 33 29 9 89 22 38 44 70 14 11 60 48 15 13 48 12 23 28 42 18 27 21 43 57 96 34 2 58 73 52 70 31 76 24 82 64 39 100 75 49 56 79 14 97 92 6 33 22 3 47 8 1 32 78 4 90 45 59 44 ...
output:
882477706
result:
ok single line: '882477706'
Test #2:
score: 0
Accepted
time: 37ms
memory: 8128kb
input:
100 74 100 24 40 64 23 44 58 28 50 75 55 66 2 78 1 31 74 21 77 35 13 91 84 85 46 39 15 32 98 46 3 41 55 29 90 57 28 35 51 84 91 2 16 34 99 81 32 51 79 43 56 41 3 29 54 98 11 4 65 29 88 61 19 99 68 36 83 47 97 79 38 5 37 22 43 65 56 17 12 34 14 54 53 18 30 26 15 72 4 34 17 70 33 92 12 100 49 5 71 14 ...
output:
151569948
result:
ok single line: '151569948'
Test #3:
score: 0
Accepted
time: 21ms
memory: 8212kb
input:
100 77 100 15 61 46 33 1 2 49 77 76 89 25 84 44 100 36 29 15 25 76 2 96 46 27 3 36 91 74 62 87 44 61 73 15 66 62 3 91 73 34 30 87 22 27 74 67 4 80 96 15 66 34 5 42 55 85 90 57 80 22 67 93 92 4 30 12 92 85 90 57 55 6 54 93 75 42 64 5 12 75 16 60 7 19 64 78 6 54 81 20 63 14 8 81 39 60 71 7 78 19 63 23...
output:
392647404
result:
ok single line: '392647404'
Test #4:
score: 0
Accepted
time: 29ms
memory: 8192kb
input:
100 59 100 47 20 24 7 42 32 44 21 35 36 33 46 3 28 14 43 25 8 11 38 29 13 19 12 34 16 5 1 45 39 22 9 30 4 2 17 47 10 23 18 41 26 27 37 6 15 31 40 47 23 33 45 31 35 9 2 42 36 5 32 38 46 15 7 10 41 43 11 17 16 27 20 26 8 3 12 40 18 13 37 28 30 1 6 24 25 39 14 29 4 47 19 34 22 44 21 47 43 10 5 21 27 11...
output:
768008715
result:
ok single line: '768008715'
Test #5:
score: 0
Accepted
time: 124ms
memory: 8120kb
input:
99 92 99 50 84 24 77 41 8 60 36 90 68 42 20 32 25 7 65 47 31 40 52 27 53 14 91 51 18 94 78 96 11 29 76 10 9 74 22 6 80 4 89 46 1 44 63 49 45 17 66 43 26 81 39 32 41 92 36 91 4 22 34 88 58 15 56 86 46 43 9 84 23 11 42 35 13 21 76 30 55 87 85 26 64 78 60 53 93 7 80 90 94 45 47 4 17 19 91 37 74 27 45 8...
output:
802784090
result:
ok single line: '802784090'
Test #6:
score: 0
Accepted
time: 121ms
memory: 8124kb
input:
99 20 100 48 51 92 35 74 59 55 97 37 96 12 53 17 68 39 79 85 54 19 23 11 87 73 72 98 67 40 47 3 52 49 1 20 83 89 5 22 36 93 82 90 48 16 41 28 25 42 14 15 59 46 82 53 77 35 51 76 65 31 33 17 12 92 74 79 52 50 84 61 44 58 95 29 7 11 86 99 67 55 40 37 64 96 93 22 88 85 13 87 9 70 59 45 32 66 6 90 14 41...
output:
569176865
result:
ok single line: '569176865'
Test #7:
score: 0
Accepted
time: 54ms
memory: 8164kb
input:
100 33 100 43 81 2 43 27 87 5 49 62 35 93 47 67 38 50 20 40 61 58 78 7 92 32 26 19 55 14 24 74 15 80 56 59 28 8 84 37 54 51 12 86 70 34 22 41 41 64 82 95 16 66 25 69 53 33 71 42 21 77 18 9 99 63 57 4 13 72 46 96 60 3 23 76 90 39 29 100 68 6 85 83 75 44 30 65 11 41 12 28 14 5 98 88 67 73 15 78 26 56 ...
output:
131562182
result:
ok single line: '131562182'
Test #8:
score: 0
Accepted
time: 54ms
memory: 8192kb
input:
100 59 100 41 93 11 66 44 35 71 4 63 60 95 24 40 45 61 87 33 43 83 89 3 99 32 34 10 70 2 94 19 65 6 59 80 26 96 15 57 47 16 97 38 82 41 62 72 1 21 98 18 75 42 5 67 86 100 58 9 7 55 91 53 23 76 22 48 30 56 39 52 92 28 29 46 14 64 51 12 54 90 41 68 81 69 31 37 39 91 75 58 86 100 1 18 55 74 27 53 50 42...
output:
740370160
result:
ok single line: '740370160'
Test #9:
score: 0
Accepted
time: 12ms
memory: 8204kb
input:
100 76 100 10 95 41 64 36 42 84 58 91 2 53 14 43 93 80 7 89 97 73 39 32 68 3 57 8 23 13 34 38 20 25 83 29 19 10 69 4 81 50 60 14 66 51 49 5 77 75 56 70 13 54 79 14 59 94 17 52 98 37 27 65 61 45 78 96 44 85 9 86 21 11 28 67 11 99 92 87 82 47 46 12 17 26 1 33 13 10 50 35 81 60 20 16 29 4 83 25 69 19 1...
output:
106948111
result:
ok single line: '106948111'
Test #10:
score: 0
Accepted
time: 27ms
memory: 8108kb
input:
100 54 100 18 75 12 74 2 15 84 97 95 66 49 36 76 31 68 58 35 27 7 27 32 17 6 19 38 40 80 93 61 29 67 69 18 53 83 62 92 11 52 77 46 55 99 22 82 3 5 36 65 79 33 16 60 45 8 51 72 23 89 96 13 48 10 91 4 57 14 42 78 20 100 86 56 81 26 73 41 50 34 63 88 24 90 1 20 58 30 35 59 84 28 27 95 68 31 66 64 76 36...
output:
600809990
result:
ok single line: '600809990'
Test #11:
score: 0
Accepted
time: 4ms
memory: 8112kb
input:
100 1 100 8 2 4 9 13 19 21 68 82 6 3 6 8 11 31 100 2 12 90 6 5 7 10 15 20 73 3 14 47 49 2 23 86 1 7 1 16 2 17 79 2 18 94 6 24 26 34 38 78 80 2 37 43 3 85 87 93 2 61 62 3 28 33 60 1 32 1 30 1 27 1 22 1 81 2 44 83 2 42 50 2 25 45 1 36 2 40 46 3 41 75 91 1 84 3 29 35 63 2 55 58 2 71 99 1 31 1 66 1 88 1...
output:
678212895
result:
ok single line: '678212895'
Test #12:
score: 0
Accepted
time: 5ms
memory: 8156kb
input:
100 1 99 5 2 5 6 7 26 6 3 4 8 35 47 82 5 11 12 14 19 27 1 4 1 9 6 13 21 49 50 56 86 5 10 22 28 29 48 2 15 55 3 16 17 100 1 10 2 38 66 1 54 1 13 1 94 3 23 32 91 4 18 42 46 61 3 60 63 97 4 20 37 39 88 2 33 52 1 20 4 24 31 36 62 1 22 2 25 30 3 34 45 89 1 25 2 40 92 1 27 1 28 1 29 1 30 2 43 58 2 44 64 1...
output:
71269815
result:
ok single line: '71269815'