結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー eitahoeitaho
提出日時 2015-08-20 22:12:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 787 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 24,948 KB
最終ジャッジ日時 2023-09-25 13:59:12
合計ジャッジ時間 16,997 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 1,810 ms
11,548 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 18 ms
7,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

LenA = 4
LenB = 7
A = "good"
B = "problem"


def solve(S):
    N = len(S)
    sumB = [0] * N

    for i in range(LenB, N):
        sumB[i] = sumB[i - 1]
        if S[i - LenB: i] == B:
            sumB[i] += 1
    minAmoves = [N] * N
    for i in range(0, N - LenA + 1):
        count = 0
        for d in range(LenA):
            if S[i + d] != A[d]:
                count += 1
        minAmoves[i] = count + sumB[i]
        minAmoves[i] = min(minAmoves[i], minAmoves[i - 1])
    ans = N
    for i in range(LenA, N - LenB + 1):
        count = 0
        for d in range(LenB):
            if S[i + d] != B[d]:
                count += 1
        ans = min(ans, count + minAmoves[i - LenA])

    return ans

T = int(input())
S = [input() for i in range(T)]
for s in S:
    print(solve(s))
0