結果

問題 No.345 最小チワワ問題
ユーザー gya9_
提出日時 2018-07-19 19:21:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 427 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-10-01 05:06:17
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

S = input()
# S = "ccwwccw"

cpos = [i for i, x in enumerate(S) if x == "c"]

wpos = [i for i, x in enumerate(S) if x == "w"]

ans = []

if len(cpos) == 0 or len(wpos) <= 1:
    print(-1)
    sys.exit()

for i in cpos:

    wpostemp = [j for j in wpos if j > i]

    if len(wpostemp) <= 1:
        break

    anstemp = wpostemp[1] - i + 1
    ans.append(anstemp)

if not ans:
    print(-1)
else:
    print(min(ans))
0