結果
問題 | No.345 最小チワワ問題 |
ユーザー |
|
提出日時 | 2016-02-26 22:58:42 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 582 bytes |
コンパイル時間 | 224 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-09-25 11:25:16 |
合計ジャッジ時間 | 2,019 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
S = input() def solve(S): if S.count('c') == 0 or S.count('w') < 2: return -1 n = len(S) record = float('inf') for head in range(n): for tail in range(head + 1, n + 1): if has_chiwawa(S[head:tail]): if tail - head < record: record = tail - head if record == float('inf'): return -1 return record def has_chiwawa(S): c = 0 w = 0 for s in S: if s == 'c' and c == 0: c += 1 if c and s == 'w': w += 1 return w >= 2 print(solve(S))