結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー mkawa2mkawa2
提出日時 2020-01-30 18:00:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,052 KB
実行使用メモリ 39,940 KB
最終ジャッジ日時 2023-10-14 08:37:03
合計ジャッジ時間 10,194 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

from itertools import *
from bisect import *
from math import *
from collections import *
from heapq import *
from random import *
import numpy as np
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, 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)]

def main():
    def cnt_change(s, t):
        n = len(s)
        m = len(t)
        res = [inf] * n
        for i in range(n - m + 1):
            change = 0
            for c0, c1 in zip(s[i:], t):
                if c0 != c1: change += 1
            res[i] = change
        return res

    t = II()
    for _ in range(t):
        s = input()
        n = len(s)
        cg = cnt_change(s, "good")
        cp = cnt_change(s, "problem")
        #print(cg)
        #print(cp)
        mn = inf
        for i in range(n):
            if cg[i] < mn:
                mn = cg[i]
            else:
                cg[i] = mn
        mn = inf
        for i in range(n-1,-1,-1):
            if cp[i] < mn:
                mn = cp[i]
            else:
                cp[i] = mn
        #print(cg)
        #print(cp)
        ans=inf
        for i in range(n-6):
            val=cg[i]+cp[i+4]
            if val<ans:ans=val
        print(ans)


main()
0