結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー tnoda_tnoda_
提出日時 2015-08-31 15:16:20
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 947 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 6,516 KB
実行使用メモリ 30,252 KB
最終ジャッジ日時 2023-09-25 21:08:19
合計ジャッジ時間 20,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 12 ms
5,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin


def solve(S):
    L = len(S)
    # Leading problems
    lp = [0] * L
    for i in xrange(L-6):
        flag = True
        lp[i+6] = lp[i+5]
        for j in xrange(7):
            if S[i+j] != "problem"[j]:
                flag = False
        if flag:
            lp[i+6] += 1
    # good cost at i
    good = [4] * L
    for i in xrange(L-10):
        for j in xrange(4):
            if S[i+j] == "good"[j]:
                good[i] -= 1
    # problem cost at i
    problem = [7] * L
    for i in xrange(L-6):
        for j in xrange(7):
            if S[i+j] == "problem"[j]:
                problem[i] -= 1
    for i in xrange(L-6, -1, -1):
        problem[i] = min(problem[i+1], problem[i])
    ans = good[0] + problem[4]
    for i in xrange(1, L-10):
        ans = min(ans, good[i] + problem[i+4] + lp[i-1])
    print(ans)


lines = stdin.read().split('\n')

T = int(lines[0])
for i in xrange(T):
    solve(lines[i+1])
0