結果

問題 No.252 "良問"(良問とは言っていない (2)
コンテスト
ユーザー rlangevin
提出日時 2023-10-03 20:19:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 943 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 292 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 129,660 KB
最終ジャッジ日時 2026-04-03 17:10:27
合計ジャッジ時間 5,090 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 MLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

M = int(input())
for _ in range(M):
    S = list(input())
    N = len(S)
    T = [0] * 8
    problem = "problem"
    for i in range(4, N - 7):
        cnt = 0
        for j in range(7):
            cnt += int(S[i + j] != problem[j])
        T[cnt] += 1
    ans = 10 ** 18
    good = "good"
    problem_cnt = 0
    for i in range(N - 11):
        cnt = problem_cnt
        for j in range(4):
            cnt += int(S[i + j] != good[j])
        temp = 10 ** 18
        for j in range(8):
            if T[j]:
                temp = j
                break
        ans = min(ans, cnt + temp)
        cnt = 0
        for j in range(7):
            if i + 4 + j >= N:
                break
            cnt += int(S[i + 4 + j] != problem[j])
        T[cnt] -= 1
        
        if i >= 6:
            if S[i-6:i+1] == list(problem):
                problem_cnt += 1
                
    print(ans)            
0