結果
| 問題 | No.252 "良問"(良問とは言っていない (2) | 
| コンテスト | |
| ユーザー |  mkawa2 | 
| 提出日時 | 2020-01-30 21:53:21 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                TLE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,913 bytes | 
| コンパイル時間 | 96 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 27,744 KB | 
| 最終ジャッジ日時 | 2024-09-16 03:58:13 | 
| 合計ジャッジ時間 | 15,041 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 2 TLE * 5 | 
ソースコード
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()
            
            
            
        