結果

問題 No.345 最小チワワ問題
ユーザー miya145592miya145592
提出日時 2023-05-03 16:37:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 326 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 54,040 KB
最終ジャッジ日時 2024-05-01 14:31:26
合計ジャッジ時間 2,087 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,136 KB
testcase_01 AC 36 ms
54,040 KB
testcase_02 AC 35 ms
53,816 KB
testcase_03 AC 35 ms
52,352 KB
testcase_04 AC 34 ms
53,700 KB
testcase_05 AC 34 ms
52,800 KB
testcase_06 AC 35 ms
52,628 KB
testcase_07 AC 34 ms
53,572 KB
testcase_08 AC 34 ms
52,468 KB
testcase_09 AC 32 ms
52,884 KB
testcase_10 AC 32 ms
53,020 KB
testcase_11 AC 32 ms
52,772 KB
testcase_12 AC 35 ms
52,532 KB
testcase_13 AC 32 ms
52,312 KB
testcase_14 AC 33 ms
52,680 KB
testcase_15 AC 33 ms
52,504 KB
testcase_16 AC 33 ms
53,976 KB
testcase_17 AC 33 ms
52,772 KB
testcase_18 AC 33 ms
52,896 KB
testcase_19 AC 32 ms
52,648 KB
testcase_20 AC 33 ms
52,140 KB
testcase_21 AC 34 ms
53,724 KB
testcase_22 AC 33 ms
52,876 KB
testcase_23 AC 33 ms
52,972 KB
testcase_24 AC 34 ms
53,288 KB
testcase_25 AC 36 ms
53,236 KB
testcase_26 AC 35 ms
52,200 KB
testcase_27 AC 34 ms
52,948 KB
testcase_28 AC 35 ms
52,832 KB
testcase_29 AC 33 ms
53,360 KB
testcase_30 AC 32 ms
52,956 KB
testcase_31 AC 33 ms
53,600 KB
権限があれば一括ダウンロードができます

ソースコード

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