結果
問題 | No.2964 Obstruction Bingo |
ユーザー | 遭難者 |
提出日時 | 2024-10-26 23:09:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,247 ms / 2,468 ms |
コード長 | 1,575 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 77,884 KB |
最終ジャッジ日時 | 2024-10-26 23:58:49 |
合計ジャッジ時間 | 28,429 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,652 KB |
testcase_01 | AC | 38 ms
52,748 KB |
testcase_02 | AC | 58 ms
65,980 KB |
testcase_03 | AC | 38 ms
52,740 KB |
testcase_04 | AC | 47 ms
61,864 KB |
testcase_05 | AC | 71 ms
71,548 KB |
testcase_06 | AC | 480 ms
77,532 KB |
testcase_07 | AC | 146 ms
76,840 KB |
testcase_08 | AC | 383 ms
77,552 KB |
testcase_09 | AC | 117 ms
76,608 KB |
testcase_10 | AC | 290 ms
76,892 KB |
testcase_11 | AC | 357 ms
77,212 KB |
testcase_12 | AC | 679 ms
77,332 KB |
testcase_13 | AC | 181 ms
76,776 KB |
testcase_14 | AC | 182 ms
77,252 KB |
testcase_15 | AC | 100 ms
76,748 KB |
testcase_16 | AC | 256 ms
77,296 KB |
testcase_17 | AC | 228 ms
77,232 KB |
testcase_18 | AC | 214 ms
76,724 KB |
testcase_19 | AC | 314 ms
76,980 KB |
testcase_20 | AC | 430 ms
77,528 KB |
testcase_21 | AC | 668 ms
77,488 KB |
testcase_22 | AC | 256 ms
77,320 KB |
testcase_23 | AC | 171 ms
77,172 KB |
testcase_24 | AC | 75 ms
72,332 KB |
testcase_25 | AC | 917 ms
77,588 KB |
testcase_26 | AC | 930 ms
77,636 KB |
testcase_27 | AC | 941 ms
77,384 KB |
testcase_28 | AC | 912 ms
77,508 KB |
testcase_29 | AC | 956 ms
77,784 KB |
testcase_30 | AC | 890 ms
77,396 KB |
testcase_31 | AC | 962 ms
77,760 KB |
testcase_32 | AC | 933 ms
77,628 KB |
testcase_33 | AC | 908 ms
77,672 KB |
testcase_34 | AC | 941 ms
77,500 KB |
testcase_35 | AC | 924 ms
77,148 KB |
testcase_36 | AC | 962 ms
77,884 KB |
testcase_37 | AC | 947 ms
77,640 KB |
testcase_38 | AC | 1,247 ms
77,596 KB |
testcase_39 | AC | 929 ms
77,624 KB |
testcase_40 | AC | 914 ms
77,568 KB |
testcase_41 | AC | 904 ms
77,624 KB |
testcase_42 | AC | 1,222 ms
77,284 KB |
testcase_43 | AC | 886 ms
77,324 KB |
testcase_44 | AC | 913 ms
77,836 KB |
testcase_45 | AC | 176 ms
77,036 KB |
testcase_46 | AC | 49 ms
63,804 KB |
testcase_47 | AC | 47 ms
62,720 KB |
testcase_48 | AC | 66 ms
69,732 KB |
testcase_49 | AC | 168 ms
76,840 KB |
testcase_50 | AC | 359 ms
77,464 KB |
testcase_51 | AC | 833 ms
77,620 KB |
ソースコード
import sys input = sys.stdin.readline L, K = map(int, input().split()) S = [ord(c) - ord("a") for c in input().strip()] T = [ord(c) - ord("a") for c in input().strip()] a = list(map(int, input().split())) a_sum = sum(a) MOD = 998244353 a_sum_inv = pow(a_sum, MOD - 2, MOD) for i in range(26): a[i] = a[i] * a_sum_inv % MOD d = [[0 for _ in range(2 * L - 1)] for _ in range(L)] d[0][L - 1] = 1 x, y = 0, 0 dd = [[0 for _ in range(2 * L - 1)] for _ in range(L)] for _ in range(K): for i in range(L): for j in range(2 * L - 1): dd[i][j] = 0 for i in range(L): for j in range(2 * L - 1): if d[i][j] == 0: continue c1, c2, c3, c4 = 0, 0, 0, 0 for c in range(26): xb, yb = S[i] == c, T[(i + j - L + 1) % L] == c if xb and yb: c1 += a[c] elif xb: c2 += a[c] elif yb: c3 += a[c] else: c4 += a[c] ad = d[i][j] * a[c] % MOD dd[(i + 1) % L][j] += d[i][j] * c1 % MOD if j == 0: x += d[i][j] * c2 % MOD else: dd[(i + 1) % L][j - 1] += d[i][j] * c2 % MOD if j == 2 * L - 2: y += d[i][j] * c3 % MOD else: dd[i][j + 1] += d[i][j] * c3 % MOD dd[i][j] += d[i][j] * c4 % MOD for i in range(L): for j in range(2 * L - 1): d[i][j] = dd[i][j] % MOD print(x % MOD, y % MOD)