結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー maspymaspy
提出日時 2020-03-07 00:34:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 815 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,388 KB
最終ジャッジ日時 2024-04-22 11:35:18
合計ジャッジ時間 5,954 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 984 ms
49,388 KB
testcase_01 TLE -
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 numpy as np


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


# %%
def solve(S):
    S = np.array(list(S))
    L = len(S)
    P = np.zeros(L - 6, np.int32)
    for i, ch in enumerate('problem'):
        P += 1 * (S[i: L - 6 + i] != ch)

    G = np.zeros(L - 4, np.int32)
    for i, ch in enumerate('good'):
        G += 1 * (S[i: L - 4 + i] != ch)

    ind = np.where(P == 0)[0] + 7
    ind = ind[ind < len(G)]
    add = np.zeros_like(G)
    add[ind] += 1
    np.cumsum(add, out=add)

    G += add
    INF = 10 ** 7
    G = np.concatenate([[INF]*4, G])
    return (np.minimum.accumulate(G[:L - 6]) + P).min()

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


# %%
0