結果

問題 No.345 最小チワワ問題
ユーザー convexineq
提出日時 2021-02-01 17:57:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 384 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 54,292 KB
最終ジャッジ日時 2024-06-29 22:53:55
合計ジャッジ時間 2,243 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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