結果
問題 | No.2964 Obstruction Bingo |
ユーザー | detteiuu |
提出日時 | 2024-11-16 16:57:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,554 ms / 2,468 ms |
コード長 | 2,425 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 159,592 KB |
最終ジャッジ日時 | 2024-11-16 16:58:47 |
合計ジャッジ時間 | 40,448 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,608 KB |
testcase_01 | AC | 48 ms
59,264 KB |
testcase_02 | AC | 50 ms
60,800 KB |
testcase_03 | AC | 45 ms
59,264 KB |
testcase_04 | AC | 47 ms
59,776 KB |
testcase_05 | AC | 114 ms
77,612 KB |
testcase_06 | AC | 646 ms
113,284 KB |
testcase_07 | AC | 212 ms
81,340 KB |
testcase_08 | AC | 506 ms
103,708 KB |
testcase_09 | AC | 151 ms
79,324 KB |
testcase_10 | AC | 373 ms
94,496 KB |
testcase_11 | AC | 514 ms
107,596 KB |
testcase_12 | AC | 941 ms
136,456 KB |
testcase_13 | AC | 244 ms
85,724 KB |
testcase_14 | AC | 207 ms
83,840 KB |
testcase_15 | AC | 144 ms
78,592 KB |
testcase_16 | AC | 363 ms
94,920 KB |
testcase_17 | AC | 301 ms
90,152 KB |
testcase_18 | AC | 313 ms
88,844 KB |
testcase_19 | AC | 425 ms
103,860 KB |
testcase_20 | AC | 685 ms
107,568 KB |
testcase_21 | AC | 1,254 ms
138,808 KB |
testcase_22 | AC | 357 ms
99,540 KB |
testcase_23 | AC | 228 ms
87,036 KB |
testcase_24 | AC | 127 ms
77,464 KB |
testcase_25 | AC | 1,423 ms
158,476 KB |
testcase_26 | AC | 1,554 ms
159,284 KB |
testcase_27 | AC | 1,281 ms
158,568 KB |
testcase_28 | AC | 1,239 ms
159,184 KB |
testcase_29 | AC | 1,241 ms
159,060 KB |
testcase_30 | AC | 1,317 ms
159,124 KB |
testcase_31 | AC | 1,298 ms
159,592 KB |
testcase_32 | AC | 1,235 ms
158,952 KB |
testcase_33 | AC | 1,211 ms
159,204 KB |
testcase_34 | AC | 1,287 ms
159,388 KB |
testcase_35 | AC | 1,457 ms
158,608 KB |
testcase_36 | AC | 1,282 ms
159,340 KB |
testcase_37 | AC | 1,273 ms
158,560 KB |
testcase_38 | AC | 1,541 ms
158,736 KB |
testcase_39 | AC | 1,524 ms
158,612 KB |
testcase_40 | AC | 1,232 ms
158,864 KB |
testcase_41 | AC | 1,265 ms
159,356 KB |
testcase_42 | AC | 1,479 ms
158,232 KB |
testcase_43 | AC | 1,286 ms
159,240 KB |
testcase_44 | AC | 1,266 ms
158,992 KB |
testcase_45 | AC | 221 ms
83,352 KB |
testcase_46 | AC | 62 ms
65,920 KB |
testcase_47 | AC | 63 ms
66,176 KB |
testcase_48 | AC | 95 ms
73,344 KB |
testcase_49 | AC | 233 ms
84,164 KB |
testcase_50 | AC | 486 ms
102,496 KB |
testcase_51 | AC | 1,126 ms
153,288 KB |
ソースコード
L, K = map(int, input().split()) S = input() T = input() A = list(map(int, input().split())) MOD = 998244353 def inverse(n, d): return n * pow(d, -1, MOD) % MOD def code(s): return ord(s)-ord("a") sumA = sum(A) P = [] for i in range(26): P.append(inverse(A[i], sumA)) dp = [[[[0]*(K+1) for _ in range(L*2)] for _ in range(L*2)] for _ in range(2)] dp[0][0][0][0] = 1 nana, minsa = 0, 0 for i in range(K): for j in range(2): for k in range(L*2): for l in range(L*2): if dp[j][k][l][i] == 0: continue if j == 0 and (k-L)%(L*2) == l: nana += dp[j][k][l][i] nana %= MOD continue if j == 1 and (l-L)%(L*2) == k: minsa += dp[j][k][l][i] minsa %= MOD continue if S[k%L] != T[l%L]: if j == 1 and (k+1)%(L*2) == l: dp[0][(k+1)%(L*2)][l][i+1] += dp[j][k][l][i]*P[code(S[k%L])]%MOD dp[0][(k+1)%(L*2)][l][i+1] %= MOD else: dp[j][(k+1)%(L*2)][l][i+1] += dp[j][k][l][i]*P[code(S[k%L])]%MOD dp[j][(k+1)%(L*2)][l][i+1] %= MOD if j == 0 and k == l: dp[1][k][(l+1)%(L*2)][i+1] += dp[j][k][l][i]*P[code(T[l%L])]%MOD dp[1][k][(l+1)%(L*2)][i+1] %= MOD else: dp[j][k][(l+1)%(L*2)][i+1] += dp[j][k][l][i]*P[code(T[l%L])]%MOD dp[j][k][(l+1)%(L*2)][i+1] %= MOD dp[j][k][l][i+1] += dp[j][k][l][i]*((1-P[code(S[k%L])]-P[code(T[l%L])])%MOD)%MOD dp[j][k][l][i+1] %= MOD else: dp[j][(k+1)%(L*2)][(l+1)%(L*2)][i+1] += dp[j][k][l][i]*P[code(S[k%L])]%MOD dp[j][(k+1)%(L*2)][(l+1)%(L*2)][i+1] %= MOD dp[j][k][l][i+1] += dp[j][k][l][i]*((1-P[code(S[k%L])])%MOD)%MOD dp[j][k][l][i+1] %= MOD for i in range(2): for j in range(L*2): for k in range(L*2): if i == 0 and (j-L)%(L*2) == k: nana += dp[i][j][k][-1] nana %= MOD if i == 1 and (k-L)%(L*2) == j: minsa += dp[i][j][k][-1] minsa %= MOD print(nana, minsa)