QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283610 | #3242. 骰子旅行 | iorit | WA | 55ms | 7868kb | C++14 | 3.2kb | 2023-12-14 21:54:56 | 2023-12-14 21:54:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace IO {
#if ONLINE_JUDGE
#define getc() (IS == IT && (IT = (IS = ibuf) + fread(ibuf, 1, IL, stdin), IS == IT) ? EOF : *IS++)
#else
#define getc() getchar()
#endif
const int IL = 1 << 21, OL = 1 << 21;
int olen = 0;
char ibuf[IL], *IS = ibuf, *IT = ibuf, obuf[OL];
inline int read() {
register char ch = getc(); register int x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
return x * f;
}
inline double readdb() {
register char ch = getc(); register double x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
if(ch == '.') {
register double b = 0.1;
ch = getc();
while(isdigit(ch)) x += (ch - 48) * b, b *= 0.1, ch = getc();
}
return x * f;
}
inline int readstr(char *s) {
register char ch = getc(); register int len = 0;
while(!isalpha(ch)) ch = getc();
while(isalpha(ch)) s[++len] = ch, ch = getc();
return len;
}
inline void flush() { fwrite(obuf, 1, olen, stdout); olen = 0; }
inline void putc(register char ch) { obuf[olen++] = ch; }
template<class T>
inline void write(register T x) {
if(x < 0) obuf[olen++] = '-', x = -x;
if(x > 9) write(x / 10);
obuf[olen++] = x % 10 + 48;
}
} using namespace IO;
const int N = 2e2 + 10, mod = 998244353;
int n, s0, t;
int st[N][N], m[N], l[N][N], inv[N], f[N][N], ans;
//st[i][j] j 步走到 i 概率
//f[x][i][j] x 出发 j 步走到 i 且不经过 x 概率
int qpow(int a, int k) {
int res = 1;
while(k) {
if(k & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
k >>= 1;
}
return res;
}
signed main() {
n = read(), s0 = read(), t = read();
inv[1] = 1;
for(int i = 2; i <= 100; i++)
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
st[0][s0] = 1;
for(int i = 1; i <= n; i++) {
m[i] = read();
for(int j = 1; j <= m[i]; j++)
l[i][j] = read();
}
for(int i = 0; i < t; i++)
for(int j = 1; j <= n; j++)
for(int k = 1; k <= m[j]; k++)
st[i + 1][l[j][k]] = (st[i + 1][l[j][k]] + st[i][j]) % mod;
for(int i = 1; i <= t; i++) {
int s = 0;
// for(int j = 1; j <= n; j++)
// cout << i << " " << j << " " << st[i][j] << endl;
for(int j = 1; j <= n; j++) s = (s + st[i][j]) % mod;
s = qpow(s, mod - 2);
for(int j = 1; j <= n; j++) st[i][j] = 1ll * st[i][j] * s % mod;
// cout << i << " " << j << " " << st[i][j] << endl;
}
for(int i= 1; i <= n; i++)
for(int j = 0; j <= t; j++)
cout << i << " " << j << " " << st[j][i] << endl;
for(int i = 1; i <= n; i++) {
memset(f, 0, sizeof(f));
for(int j = 1; j <= m[i]; j++)
f[1][l[i][j]] = 1ll * inv[m[i]] * l[i][j] % mod;
for(int j = 1; j < t; j++)
for(int k = 1; k <= n; k++) {
if(k == i) continue;
for(int s = 1; s <= m[k]; s++)
f[j + 1][l[k][s]] = (f[j + 1][l[k][s]] + 1ll * inv[m[k]] * f[j][k]) % mod;
}
// cout << f[1][s0] << endl;
// for(int j = 1; j )
for(int j = 0; j <= t; j++)
for(int k = 1; j + k <= t; k++)
ans = (ans + 1ll * st[j][i] * f[k][i]) % mod;
}
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 55ms
memory: 7868kb
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:
1 0 0 1 1 0 1 2 83712864 1 3 184666172 1 4 513659284 1 5 608625182 1 6 676293426 1 7 513645312 1 8 243694429 1 9 385486151 1 10 944853461 1 11 755449693 1 12 3479229 1 13 715743962 1 14 339599718 1 15 774138986 1 16 654829079 1 17 760404190 1 18 840013622 1 19 465965215 1 20 159480193 1 21 347231748...
result:
wrong answer 1st lines differ - expected: '882477706', found: '1 0 0'