結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-25 01:28:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 648 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 24,760 KB
最終ジャッジ日時 2023-09-23 04:07:03
合計ジャッジ時間 18,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 WA -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def haming(str1, str2):
    return len([1 for c1, c2 in zip(str1, str2) if c1 != c2])

def solve(S, string1, string2):
    n = len(S)
    len1 = len(string1)
    len2 = len(string2)
    dp1 = [len1] * n # good
    dp2 = [len2] * n # problem
    for tail in range(len1, n-len2 + 1):
        dp1[tail] = min(dp1[tail - 1], haming(string1, S[tail - len1:tail]))
    for head in range(n-len2, len1 - 1, -1):
        dp2[head] = min(dp2[head + 1], haming(string2, S[head:head + len2]))
    return min(dp1[i] + dp2[i] for i in range(len1, n - len2 + 1))
        

T = int(input())
for t in range(T):
    S = input()
    print(solve(S, 'good', 'problem'))
0