結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-25 05:15:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 731 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 95,052 KB
最終ジャッジ日時 2023-09-23 04:36:19
合計ジャッジ時間 4,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 484 ms
95,052 KB
testcase_03 AC 251 ms
94,852 KB
testcase_04 AC 427 ms
94,728 KB
testcase_05 AC 465 ms
94,900 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(S, string1, string2):
    n = len(S)
    len1 = len(string1)
    len2 = len(string2)
    dp1 = [0] * n # good
    dp2 = [0] * n # problem
    dp1[len1-1] = len1
    dp2[n-len2+1] = len2
    for tail in range(len1, n-len2 + 1):
        dp1[tail] = min(dp1[tail - 1], len([1 for c1, c2 in zip(string1, S[tail - len1:tail]) if c1 != c2]))
        if not dp1[tail]: break
    for head in range(n-len2, len1 - 1, -1):
        dp2[head] = min(dp2[head + 1], len([1 for c1, c2 in zip(string2, S[head:head + len2]) if c1 != c2]))
        if not dp2[head]: break
    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