結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:08:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 793 bytes |
| コンパイル時間 | 163 ms |
| コンパイル使用メモリ | 82,340 KB |
| 実行使用メモリ | 59,320 KB |
| 最終ジャッジ日時 | 2025-03-20 21:09:09 |
| 合計ジャッジ時間 | 2,608 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
S = input().strip()
min_length = float('inf')
# Find all positions of 'c'
c_positions = [i for i, char in enumerate(S) if char == 'c']
for i in c_positions:
# Find the first 'w' after position i
j = -1
for idx in range(i + 1, len(S)):
if S[idx] == 'w':
j = idx
break
if j == -1:
continue # No first 'w' found
# Find the second 'w' after position j
k = -1
for idx in range(j + 1, len(S)):
if S[idx] == 'w':
k = idx
break
if k == -1:
continue # No second 'w' found
# Calculate the length of the substring
current_length = k - i + 1
if current_length < min_length:
min_length = current_length
print(min_length if min_length != float('inf') else -1)
lam6er