結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー convexineq
提出日時 2021-02-01 17:57:47
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 384 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 217 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 52,480 KB
最終ジャッジ日時 2026-03-19 14:14:54
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

s = input()
from bisect import bisect_left
C = []
W = []
for i,c in enumerate(s):
    if c=="c":
        C.append(-i)
    elif c=="w":
        W.append(i)
C = C[::-1]
ans = INF = 500
lc,lw = len(C),len(W)
for i in W:
    v = bisect_left(C,-i)
    if v == lc: continue
    w = bisect_left(W,i+1)
    if w == lw: continue
    ans = min(ans,W[w]+C[v]+1)

print(ans if ans != INF else -1)
0