結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー mkawa2mkawa2
提出日時 2020-01-30 21:53:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,771 ms / 2,000 ms
コード長 1,913 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 25,296 KB
最終ジャッジ日時 2023-10-14 08:51:37
合計ジャッジ時間 13,103 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,715 ms
8,920 KB
testcase_01 AC 1,359 ms
9,136 KB
testcase_02 AC 1,761 ms
13,952 KB
testcase_03 AC 1,771 ms
25,236 KB
testcase_04 AC 1,763 ms
25,296 KB
testcase_05 AC 1,765 ms
25,172 KB
testcase_06 AC 22 ms
8,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    inf = 10 ** 9
    n = II()
    for _ in range(n):
        s = SI()
        n = len(s)
        # 各位置でのproblemとの変更回数を求める
        cntp = [inf] * n
        for i in range(n - 6):
            ch = 0
            for c0, c1 in zip("problem", s[i:i + 7]):
                if c0 != c1: ch += 1
            cntp[i] = ch
        #print(cntp)
        # 左から何個のproblemがあるか数えておく
        zero = 0
        cnt_zero = [0] * n
        for i in range(n):
            if cntp[i] == 0: zero += 1
            cnt_zero[i] = zero
        #print(cnt_zero)
        # ある位置から右を見たときのproblemの変更最小値
        for i in range(n - 1, 0, -1):
            if cntp[i] < cntp[i - 1]: cntp[i - 1] = cntp[i]
        #print(cntp)
        # 各位置にgoodの先頭を持って行ったときの変更回数を求め、最小値を求める
        ans=inf
        for i in range(n - 10):
            ch = 0
            for c0, c1 in zip("good", s[i:i + 4]):
                if c0 != c1: ch += 1
            cur=ch+cntp[i+4]+(cnt_zero[i-7] if i>=7 else 0)
            if cur<ans:ans=cur
        print(ans)

main()
0