結果

問題 No.345 最小チワワ問題
ユーザー しらっ亭
提出日時 2016-02-27 20:44:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-25 11:31:55
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    S = input()
    L = len(S)

    ans = 114514
    for i, c in enumerate(S):
        if c == 'c':
            nw = 0
            for j in range(i + 1, L):
                w = S[j]
                if w == 'w':
                    nw += 1
                    if nw >= 2:
                        ans = min(ans, j - i + 1)
    if ans == 114514:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    solve()
0