結果

問題 No.150 "良問"(良問とは言っていない
ユーザー togatoga
提出日時 2015-09-12 15:26:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 739 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-11 01:56:25
合計ジャッジ時間 1,999 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())



for i in range(T):
    S = input()
    
    pre = [1 << 30] * 110
    post = [1 << 30] * 110

    for y in range(3, len(S)):
        cost = 0
        if (S[y - 3] != 'g'):
            cost += 1
        if (S[y - 2] != 'o'):
            cost += 1
        if (S[y - 1] != 'o'):
            cost += 1
        if (S[y] != 'd'):        
            cost += 1
        pre[y] = min(pre[y - 1], cost)
        
    for y in range(len(S) - 7, 0, -1):
        cost = 0
        for index,s in enumerate("problem"):
            if (S[y + index] != s):
                cost += 1
        post[y] = min(post[y + 1], cost)
        
    ans = 1 << 30
    for i in range(101):
        ans = min(ans, pre[i] + post[i + 1])
    print (ans)
0