結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー mkawa2mkawa2
提出日時 2020-01-30 21:23:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,954 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 110,908 KB
最終ジャッジ日時 2023-10-14 08:50:47
合計ジャッジ時間 4,265 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 467 ms
81,080 KB
testcase_01 AC 464 ms
81,620 KB
testcase_02 AC 446 ms
106,668 KB
testcase_03 AC 431 ms
110,908 KB
testcase_04 AC 485 ms
110,780 KB
testcase_05 AC 489 ms
110,768 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 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)
        cntg = [inf] * n
        for i in range(n - 3):
            ch = 0
            for c0, c1 in zip("good", s[i:i + 4]):
                if c0 != c1: ch += 1
            cntg[i] = ch
        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

        cnt_zero=[0]*n
        for i in range(n-4):
            if cntg[i]==0:cnt_zero[i+4]=1
        zero=0
        for i in range(n):
            zero+=cnt_zero[i]
            cntg[i]+=zero
        cnt_zero=[0]*n
        for i in range(n-7):
            if cntp[i]==0:cnt_zero[i+7]=1
        zero=0
        for i in range(n):
            zero+=cnt_zero[i]
            cntp[i]+=zero
        #print(cntg)
        #print(cntp)
        for i in range(n - 1):
            if cntg[i] < cntg[i + 1]: cntg[i + 1] = cntg[i]
        for i in range(n - 1, 0, -1):
            if cntp[i] < cntp[i - 1]: cntp[i - 1] = cntp[i]
        #print(cntg)
        #print(cntp)
        ans = inf
        for i in range(n - 10):
            cur = cntg[i] + cntp[i + 4]
            if cur < ans: ans = cur
        print(ans)

main()
0