QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281698#3242. 骰子旅行wtcc#AC ✓387ms23988kbC++201.5kb2023-12-10 15:50:322023-12-10 15:50:33

Judging History

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

  • [2023-12-10 15:50:33]
  • 评测
  • 测评结果:AC
  • 用时:387ms
  • 内存:23988kb
  • [2023-12-10 15:50:32]
  • 提交

answer

#include<bits/stdc++.h>
#define Hatsune return
#define Miku 0
using namespace std;

typedef long long ll;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-'){f=-1;}ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48),ch=getchar();}
    return x*f;
}

const ll mod=998244353;
const ll N=110;
ll n,s,T,g[N][N][N],m[N];
ll f[N][N][N],inv[N];
bool to[N][N];inline void red(ll &x){x>=mod?x-=mod:0;}
void init(){
	for(ll i=0;i<T;i++){
		for(ll u=1;u<=n;u++){
			for(ll v=1;v<=n;v++){
				for(ll x=1;x<=n;x++){
					if(!to[v][x]) continue;
					(g[u][x][i+1]+=g[u][v][i]*inv[m[v]]%mod)%=mod;
				}
			}
		}
	}
	for(ll i=0;i<=T;i++){
		for(ll u=1;u<=n;u++){
			for(ll v=1;v<=n;v++){
				f[u][v][i]=g[u][v][i];
				for(ll k=0;k<i;k++){
					(f[u][v][i]+=mod-f[u][v][k]*g[v][v][i-k]%mod)%=mod;
				}
			}
		}
	}

}

int main(){
	n=read(),s=read(),T=read();
	inv[1]=1;for(int i=2;i<=n;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(ll i=1;i<=n;i++){
		m[i]=read();
		for(ll j=1;j<=m[i];j++){
			ll v=read();
			to[i][v]=1;
		}
	}
    for(ll i=1;i<=n;i++) g[i][i][0]=1;
	init();
	ll res=0;
	for(ll i=1;i<=T;i++){
		for(ll u=1;u<=n;u++){
			for(ll v=1;v<=n;v++){
                if(!to[v][u]) continue;
				ll p=0;
				for(int k=0;k<=T-i;++k) (p+=f[u][v][k])%=mod;
                p%=mod;
				p=p*g[s][v][i-1]%mod*inv[m[v]]%mod;
				res+=p*u%mod;
                res%=mod;
			}
		}
	}
	cout<<res;
	Hatsune Miku;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 363ms
memory: 23644kb

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

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

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

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

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

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

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

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

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

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

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

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'