結果
問題 | No.2964 Obstruction Bingo |
ユーザー | miya145592 |
提出日時 | 2024-11-16 17:45:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,387 ms / 2,468 ms |
コード長 | 2,703 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 131,692 KB |
最終ジャッジ日時 | 2024-11-16 17:46:46 |
合計ジャッジ時間 | 64,713 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,608 KB |
testcase_01 | AC | 36 ms
52,096 KB |
testcase_02 | AC | 38 ms
52,480 KB |
testcase_03 | AC | 36 ms
52,096 KB |
testcase_04 | AC | 38 ms
52,608 KB |
testcase_05 | AC | 147 ms
78,272 KB |
testcase_06 | AC | 1,212 ms
95,708 KB |
testcase_07 | AC | 325 ms
81,244 KB |
testcase_08 | AC | 929 ms
88,244 KB |
testcase_09 | AC | 246 ms
80,308 KB |
testcase_10 | AC | 767 ms
84,464 KB |
testcase_11 | AC | 914 ms
94,832 KB |
testcase_12 | AC | 1,775 ms
110,644 KB |
testcase_13 | AC | 420 ms
81,908 KB |
testcase_14 | AC | 371 ms
79,576 KB |
testcase_15 | AC | 206 ms
78,800 KB |
testcase_16 | AC | 636 ms
84,964 KB |
testcase_17 | AC | 519 ms
82,412 KB |
testcase_18 | AC | 498 ms
82,572 KB |
testcase_19 | AC | 839 ms
89,840 KB |
testcase_20 | AC | 1,039 ms
90,316 KB |
testcase_21 | AC | 1,718 ms
115,156 KB |
testcase_22 | AC | 653 ms
88,268 KB |
testcase_23 | AC | 353 ms
81,876 KB |
testcase_24 | AC | 121 ms
77,640 KB |
testcase_25 | AC | 2,256 ms
127,448 KB |
testcase_26 | AC | 2,267 ms
129,268 KB |
testcase_27 | AC | 2,308 ms
129,236 KB |
testcase_28 | AC | 2,262 ms
128,972 KB |
testcase_29 | AC | 2,290 ms
131,444 KB |
testcase_30 | AC | 2,249 ms
129,868 KB |
testcase_31 | AC | 2,208 ms
128,668 KB |
testcase_32 | AC | 2,187 ms
129,904 KB |
testcase_33 | AC | 2,226 ms
128,616 KB |
testcase_34 | AC | 2,353 ms
129,424 KB |
testcase_35 | AC | 2,387 ms
129,616 KB |
testcase_36 | AC | 2,265 ms
131,692 KB |
testcase_37 | AC | 2,350 ms
130,724 KB |
testcase_38 | AC | 2,225 ms
130,784 KB |
testcase_39 | AC | 2,248 ms
130,652 KB |
testcase_40 | AC | 2,258 ms
130,908 KB |
testcase_41 | AC | 2,208 ms
128,480 KB |
testcase_42 | AC | 2,237 ms
129,628 KB |
testcase_43 | AC | 2,262 ms
130,788 KB |
testcase_44 | AC | 2,276 ms
130,516 KB |
testcase_45 | AC | 394 ms
82,624 KB |
testcase_46 | AC | 51 ms
60,416 KB |
testcase_47 | AC | 41 ms
53,120 KB |
testcase_48 | AC | 37 ms
52,736 KB |
testcase_49 | AC | 452 ms
82,316 KB |
testcase_50 | AC | 893 ms
85,884 KB |
testcase_51 | AC | 2,032 ms
122,124 KB |
ソースコード
import sys input = sys.stdin.readline MOD = 998244353 L, K = map(int, input().split()) S = input().strip() T = input().strip() A = list(map(int, input().split())) C = sum(A) base = pow(C, MOD-2, MOD) Q = [] for a in A: Q.append(a*base%MOD) #print(Q) dp = dict() dp[(0, 0)] = 1 X = 0 Y = 0 for i in range(K): ndp = dict() for key in dp: pn, pm = key if pn-pm==L: X += dp[key] X %= MOD continue if pm-pn==L: Y += dp[key] Y %= MOD continue sn = S[pn%L] sm = T[pm%L] if sn==sm: snc = ord(sn)-ord('a') if Q[snc]>0: npn = pn+1 npm = pm+1 if npn>=L and npm>=L: npn-=L npm-=L if (npn, npm) not in ndp: ndp[(npn, npm)] = dp[key] * Q[snc] % MOD else: ndp[(npn, npm)] += dp[key] * Q[snc] % MOD ndp[(npn, npm)] %= MOD if (1-Q[snc])%MOD>0: if (pn, pm) not in ndp: ndp[(pn, pm)] = dp[key] * (1-Q[snc]) % MOD else: ndp[(pn, pm)] += dp[key] * (1-Q[snc]) % MOD ndp[(pn, pm)] %= MOD else: snc = ord(sn)-ord('a') smc = ord(sm)-ord('a') if Q[snc]>0: npn = pn+1 npm = pm if npn>=L and npm>=L: npn-=L npm-=L if (npn, npm) not in ndp: ndp[(npn, npm)] = dp[key] * Q[snc] % MOD else: ndp[(npn, npm)] += dp[key] * Q[snc] % MOD ndp[(npn, npm)] %= MOD if Q[smc]>0: npn = pn npm = pm+1 if npn>=L and npm>=L: npn-=L npm-=L if (npn, npm) not in ndp: ndp[(npn, npm)] = dp[key] * Q[smc] % MOD else: ndp[(npn, npm)] += dp[key] * Q[smc] % MOD ndp[(npn, npm)] %= MOD if (1-Q[snc]-Q[smc])%MOD>0: if (pn, pm) not in ndp: ndp[(pn, pm)] = dp[key] * (1-Q[snc]-Q[smc]) % MOD else: ndp[(pn, pm)] += dp[key] * (1-Q[snc]-Q[smc]) % MOD ndp[(pn, pm)] %= MOD dp = ndp #print(dp) #print(X, Y) for key in dp: pn, pm = key if pn-pm==L: X += dp[key] X %= MOD continue if pm-pn==L: Y += dp[key] Y %= MOD continue print(X, Y)