結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー maspymaspy
提出日時 2020-03-07 00:13:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 865 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 26,568 KB
最終ジャッジ日時 2024-04-22 11:02:06
合計ジャッジ時間 7,201 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools


# %%
T = int(readline())
words = read().decode().split()


# %%
def solve(S):
    INF = 10 ** 7
    L = len(S)
    problem = [i + 7 for i in range(L - 6) if S[i: i + 7] == 'problem']
    G = [sum(x != y for x, y in zip(S[i: i + 4], 'good')) for i in range(L)]
    add = [0] * L
    for i in problem:
        if i < L:
            add[i] += 1
    for n in range(L - 1):
        add[n + 1] += add[n]
    G = [x + y for x, y in zip(G, add)]
    P = [sum(x != y for x, y in zip(S[i:i + 7], 'problem')) for i in range(L)]
    for i in range(L - 6, L):
        P[i] = INF
    G = itertools.accumulate([INF] * 4 + G[:-4], min)
    return min(p + g for p, g in zip(P, G))


for w in words:
    print(solve(w))
0