結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー convexineq
提出日時 2021-02-01 17:57:47
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 66 ms / 2,000 ms
+ 189µs
コード長 384 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 234 ms
コンパイル使用メモリ 95,844 KB
実行使用メモリ 79,104 KB
最終ジャッジ日時 2026-08-02 01:10:05
合計ジャッジ時間 4,426 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_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