結果

問題 No.345 最小チワワ問題
ユーザー miya145592
提出日時 2023-05-03 16:37:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 326 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 52,480 KB
最終ジャッジ日時 2024-11-21 19:21:53
合計ジャッジ時間 2,371 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
S = input()
W = [0]
for s in S:
    if s=="w":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])
ans = 10**9
for i, s in enumerate(S):
    if s=="c":
        pos = bisect.bisect_left(W, W[i]+2)
        if pos<=len(S):
            ans = min(ans, pos-i)
if ans==10**9:
    print(-1)
else:
    print(ans)
0