結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-25 05:14:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 721 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 24,748 KB
最終ジャッジ日時 2023-09-23 04:34:52
合計ジャッジ時間 11,721 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 WA -
testcase_02 AC 1,421 ms
11,740 KB
testcase_03 AC 558 ms
24,676 KB
testcase_04 AC 1,243 ms
24,640 KB
testcase_05 AC 1,407 ms
24,748 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):
    print(solve(input(), 'good', 'problem'))
0