結果
| 問題 | No.2964 Obstruction Bingo |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-29 13:50:34 |
| 言語 | PyPy3 (7.3.23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,614 bytes |
| 記録 | |
| コンパイル時間 | 255 ms |
| コンパイル使用メモリ | 95,848 KB |
| 実行使用メモリ | 108,900 KB |
| 最終ジャッジ日時 | 2026-08-29 13:50:44 |
| 合計ジャッジ時間 | 6,653 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 TLE * 1 -- * 45 |
ソースコード
## https://yukicoder.me/problems/no/2964
import math
MOD = 998244353
def main():
L, K = map(int , input().split())
S = input()
T = input()
A = list(map(int, input().split()))
s_array = [ord(s) - ord("a") for s in S]
t_array = [ord(s) - ord("a") for s in T]
a_prob = [0] * 26
sum_a = sum(A)
for i in range(26):
a_prob[i] = (A[i] * pow(sum_a, MOD - 2, MOD)) % MOD
dp = {(0, 0): 1}
answer_n = 0
answer_m = 0
for _ in range(K):
new_dp = {}
for key, value in dp.items():
pn, diff = key
pm = pn + diff
for x in range(26):
if s_array[pn] == x:
new_pn = pn + 1
else:
new_pn = pn
if t_array[pm % L] == x:
new_pm = pm + 1
else:
new_pm = pm
new_diff = new_pm - new_pn
ans = a_prob[x] * value
ans %= MOD
if abs(new_diff) == L:
if new_diff > 0:
answer_m += ans
answer_m %= MOD
else:
answer_n += ans
answer_n %= MOD
else:
new_key = (new_pn % L, new_diff)
if new_key not in new_dp:
new_dp[new_key] = 0
new_dp[new_key] += ans
new_dp[new_key] %= MOD
dp = new_dp
print(answer_n, answer_m)
if __name__ == "__main__":
main()