結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー rlangevinrlangevin
提出日時 2023-10-03 20:19:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 628 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 125,944 KB
最終ジャッジ日時 2023-10-03 20:19:18
合計ジャッジ時間 5,200 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 628 ms
80,044 KB
testcase_01 AC 467 ms
80,628 KB
testcase_02 AC 557 ms
120,936 KB
testcase_03 AC 539 ms
125,944 KB
testcase_04 AC 536 ms
125,664 KB
testcase_05 AC 543 ms
125,544 KB
testcase_06 AC 83 ms
76,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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