結果
問題 | No.345 最小チワワ問題 |
ユーザー |
![]() |
提出日時 | 2020-03-29 21:55:00 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 433 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 10,240 KB |
最終ジャッジ日時 | 2025-01-02 15:50:27 |
合計ジャッジ時間 | 2,180 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import sys input=lambda: sys.stdin.readline().rstrip() S=input() n=len(S) C=[] W=[] import bisect for i in range(n): if S[i]=="c": C.append(i) if S[i]=="w": W.append(i) if not C or not W: print(-1) else: ans=float("inf") for i in range(len(W)-1): w1,w2=W[i],W[i+1] if w1<C[0]: continue else: c=C[bisect.bisect_left(C,w1)-1] ans=min(ans,w2-c+1) print(-1 if ans==float("inf") else ans)