結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー luyaowang-oss
提出日時 2026-12-02 18:43:26
言語 Python3
(3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 61 ms
コンパイル使用メモリ 14,592 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2026-12-02 18:43:30
合計ジャッジ時間 2,582 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = input()
cPos, wPos, w2Pos, minStep, temp = 0, 0, 0, 0, 0
for _ in range(S.count("c")):
    if cPos==0 and wPos==0:
        cPos = S.find("c")
        wPos = S.find("w", cPos+1)
        w2Pos = S.find("w", wPos+1)
        temp = cPos
        if cPos == -1 or w2Pos == -1 or wPos==-1:
            minStep = -1
            break
        minStep = w2Pos - cPos + 1
    else:
        cPos = S.find("c", temp+1)
        wPos = S.find("w", temp+1)  
        w2Pos = S.find("w", wPos+1)
        temp = cPos
        if (cPos == -1 or w2Pos == -1 or wPos==-1) and minStep==0:
            minStep = -1
            break
        if minStep>w2Pos - cPos + 1 and w2Pos>cPos:
            minStep = w2Pos - cPos + 1
print(minStep)
0