QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283614#3242. 骰子旅行ioritAC ✓56ms8100kbC++143.2kb2023-12-14 22:10:362023-12-14 22:10:37

Judging History

你现在查看的是最新测评结果

  • [2023-12-14 22:10:37]
  • 评测
  • 测评结果:AC
  • 用时:56ms
  • 内存:8100kb
  • [2023-12-14 22:10:36]
  • 提交

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]] + 1ll * inv[m[j]] * 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: 100
Accepted
time: 56ms
memory: 6580kb

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: 29ms
memory: 6492kb

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: 15ms
memory: 6396kb

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: 56ms
memory: 6564kb

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: 55ms
memory: 6392kb

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: 53ms
memory: 6524kb

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: 43ms
memory: 6452kb

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: 46ms
memory: 6580kb

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: 19ms
memory: 8100kb

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: 32ms
memory: 6460kb

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: 7ms
memory: 6560kb

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: 3ms
memory: 6576kb

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'