結果
問題 | No.2964 Obstruction Bingo |
ユーザー | miya145592 |
提出日時 | 2024-11-16 17:40:27 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,277 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 323,268 KB |
最終ジャッジ日時 | 2024-11-16 17:42:23 |
合計ジャッジ時間 | 113,028 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
57,216 KB |
testcase_01 | AC | 39 ms
251,228 KB |
testcase_02 | AC | 40 ms
57,600 KB |
testcase_03 | AC | 37 ms
241,740 KB |
testcase_04 | AC | 38 ms
57,728 KB |
testcase_05 | AC | 343 ms
83,404 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 431 ms
294,644 KB |
testcase_08 | TLE | - |
testcase_09 | AC | 842 ms
300,908 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 1,036 ms
323,268 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 1,380 ms
320,084 KB |
testcase_14 | AC | 1,657 ms
121,504 KB |
testcase_15 | AC | 396 ms
293,436 KB |
testcase_16 | AC | 1,037 ms
107,736 KB |
testcase_17 | AC | 755 ms
302,660 KB |
testcase_18 | AC | 1,225 ms
111,656 KB |
testcase_19 | AC | 1,042 ms
314,684 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 663 ms
95,188 KB |
testcase_23 | AC | 301 ms
295,844 KB |
testcase_24 | AC | 145 ms
82,088 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
testcase_45 | AC | 1,666 ms
124,608 KB |
testcase_46 | AC | 51 ms
65,536 KB |
testcase_47 | AC | 136 ms
75,904 KB |
testcase_48 | AC | 43 ms
52,608 KB |
testcase_49 | AC | 2,013 ms
136,780 KB |
testcase_50 | TLE | - |
testcase_51 | TLE | - |
ソースコード
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: if (pn+1, pm+1) not in ndp: ndp[(pn+1, pm+1)] = dp[key] * Q[snc] % MOD else: ndp[(pn+1, pm+1)] += dp[key] * Q[snc] % MOD ndp[(pn+1, pm+1)] %= 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: if (pn+1, pm) not in ndp: ndp[(pn+1, pm)] = dp[key] * Q[snc] % MOD else: ndp[(pn+1, pm)] += dp[key] * Q[snc] % MOD ndp[(pn+1, pm)] %= MOD if Q[smc]>0: if (pn, pm+1) not in ndp: ndp[(pn, pm+1)] = dp[key] * Q[smc] % MOD else: ndp[(pn, pm+1)] += dp[key] * Q[smc] % MOD ndp[(pn, pm+1)] %= 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)