結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー ecottea
提出日時 2023-01-26 02:45:35
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 587 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 474 ms
コンパイル使用メモリ 20,608 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-14 05:35:17
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
dump = lambda *x : print(*x, file = sys.stderr)

# cawwcww で 4 と返してしまう.
def WA():
    import re

    s = input()
    m = re.search(r'.*c.*w.*w.*?', s)
    dump(m)

    if m is None:
        return(-1)
    else:
        return(len(m.group(0)))


s = input()
n = len(s)

res = 114514

for i in range(n):
    if s[i] != 'c':
        continue

    cnt = 0
    for j in range(i+1,n):
        if s[j] == 'w':
            cnt += 1
        
        if cnt == 2:
            res = min(res, j - i + 1)
            break

if res == 114514:
    res = -1
    
print(res)
0