結果

問題 No.345 最小チワワ問題
ユーザー yuki2006
提出日時 2016-02-18 03:07:51
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 387 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 7,072 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 11:20:12
合計ジャッジ時間 1,353 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

S = raw_input()

hitC = -1
hitW = -1
mn = float("inf")
latestCWStart = -1
for i, s in enumerate(S):
    if s == "c":
        hitC = i
    if s == "w":
        if latestCWStart != -1:
            mn = min(mn, i - latestCWStart + 1)

        hitW = i
        if hitC < hitW:
            latestCWStart = hitC

if mn == float("inf"):
    print -1
else:
    print mn
0