結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
学ぶマン
|
| 提出日時 | 2025-06-08 20:25:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 1,004 bytes |
| コンパイル時間 | 550 ms |
| コンパイル使用メモリ | 82,768 KB |
| 実行使用メモリ | 54,268 KB |
| 最終ジャッジ日時 | 2025-06-08 20:25:14 |
| 合計ジャッジ時間 | 3,050 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
S = list(input())
N = len(S)
INF = 10**18
from bisect import bisect_left, bisect_right
def cnt_ika(li, x): # x 以下の要素数
return bisect_right(li, x)
def cnt_miman(li, x): # x 未満の要素数
return bisect_left(li, x)
def cnt_ijou(li, x): # x 以上の要素数
return len(li) - cnt_miman(li, x)
def cnt_choka(li, x): # x より大きい要素数
return len(li) - cnt_ika(li, x)
c_index, w_index = [], []
for i, s in enumerate(S):
if s == 'c':
c_index.append(i)
if s == 'w':
w_index.append(i)
# c を固定して、そのindex より大きい
# c = [2]
# w = [1, 5, 8]
# 2 以下に w がいつくあるか ・・・ memo
# memo + 2 番目(index: memo +2 - 1)が 右端のwのindex
limit = len(w_index)
ansl = [N + 1]
for i in c_index:
memo = cnt_ika(w_index, i)
if memo + 1 >= limit:
break
utan = w_index[memo + 1]
candi = utan - i + 1
ansl.append(candi)
ans = min(ansl)
if ans == N + 1:
ans = -1
print(ans)
学ぶマン