結果

問題 No.345 最小チワワ問題
ユーザー rpy3cpprpy3cpp
提出日時 2016-02-26 22:58:42
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 9,972 KB
最終ジャッジ日時 2023-10-26 03:30:06
合計ジャッジ時間 2,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,972 KB
testcase_01 AC 31 ms
9,972 KB
testcase_02 AC 30 ms
9,972 KB
testcase_03 AC 30 ms
9,972 KB
testcase_04 AC 29 ms
9,972 KB
testcase_05 AC 29 ms
9,972 KB
testcase_06 AC 29 ms
9,972 KB
testcase_07 AC 29 ms
9,972 KB
testcase_08 AC 29 ms
9,972 KB
testcase_09 AC 30 ms
9,972 KB
testcase_10 AC 32 ms
9,972 KB
testcase_11 AC 29 ms
9,972 KB
testcase_12 AC 29 ms
9,972 KB
testcase_13 AC 30 ms
9,972 KB
testcase_14 AC 41 ms
9,972 KB
testcase_15 AC 32 ms
9,972 KB
testcase_16 AC 30 ms
9,972 KB
testcase_17 AC 29 ms
9,972 KB
testcase_18 AC 33 ms
9,972 KB
testcase_19 AC 31 ms
9,972 KB
testcase_20 AC 29 ms
9,972 KB
testcase_21 AC 29 ms
9,972 KB
testcase_22 AC 30 ms
9,972 KB
testcase_23 AC 30 ms
9,972 KB
testcase_24 AC 29 ms
9,972 KB
testcase_25 AC 30 ms
9,972 KB
testcase_26 AC 29 ms
9,972 KB
testcase_27 AC 29 ms
9,972 KB
testcase_28 AC 29 ms
9,972 KB
testcase_29 AC 31 ms
9,972 KB
testcase_30 AC 31 ms
9,972 KB
testcase_31 AC 29 ms
9,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()

def solve(S):
    if S.count('c') == 0 or S.count('w') < 2:
        return -1
    n = len(S)
    record = float('inf')
    for head in range(n):
        for tail in range(head + 1, n + 1):
            if has_chiwawa(S[head:tail]):
                if tail - head < record:
                    record = tail - head
    if record == float('inf'):
        return -1
    return record

def has_chiwawa(S):
    c = 0
    w = 0
    for s in S:
        if s == 'c' and c == 0:
            c += 1
        if c and s == 'w':
            w += 1
    return w >= 2

print(solve(S))
0