結果

問題 No.150 "良問"(良問とは言っていない
ユーザー warashiwarashi
提出日時 2015-02-13 00:24:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-19 09:16:05
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
10,624 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 31 ms
10,496 KB
testcase_03 AC 32 ms
10,496 KB
testcase_04 AC 32 ms
10,624 KB
testcase_05 AC 32 ms
10,624 KB
testcase_06 AC 80 ms
10,624 KB
testcase_07 AC 27 ms
10,624 KB
testcase_08 AC 33 ms
10,752 KB
testcase_09 AC 27 ms
10,624 KB
testcase_10 AC 44 ms
10,624 KB
testcase_11 AC 50 ms
10,624 KB
testcase_12 AC 39 ms
10,624 KB
testcase_13 AC 45 ms
10,624 KB
testcase_14 AC 49 ms
10,624 KB
testcase_15 AC 47 ms
10,496 KB
testcase_16 AC 33 ms
10,624 KB
testcase_17 AC 37 ms
10,624 KB
testcase_18 AC 52 ms
10,624 KB
testcase_19 AC 58 ms
10,624 KB
testcase_20 AC 52 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys


def strdistance(str1, str2):
    count = 0
    for s1, s2 in zip(str1, str2):
        if s1 != s2:
            count += 1
    return count


T = int(input())
for s in sys.stdin:
    good = s.find("good")
    problem = s.find("problem")
    if good == -1:
        good = len(s) - 4
    if problem == -1:
        problem = 0
    if good < problem:
        print(0)
        continue

    distancesg = [float("inf")] * len(s)
    distancesp = [float("inf")] * len(s)

    for i in range(len(s) - 4):
        distancesg[i] = strdistance("good", s[i:i + 4])
    for i in range(len(s) - 7):
        distancesp[i] = strdistance("problem", s[i:i + 7])
    mindistance = float("inf")
    for i in range(1, len(s) - 4):
        mindistance = min(
            mindistance, min(distancesg[:i]) + min(distancesp[i + 3:]))
    print(mindistance)
0