結果

問題 No.921 ずんだアロー
ユーザー lam6er
提出日時 2025-03-20 21:21:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 581 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 92,260 KB
最終ジャッジ日時 2025-03-20 21:22:25
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

if not a:
    print(0)
    exit()

# 連続する同じ値の区間の長さを集める
current_val = a[0]
current_length = 1
segments = []
for num in a[1:]:
    if num == current_val:
        current_length += 1
    else:
        segments.append(current_length)
        current_val = num
        current_length = 1
segments.append(current_length)

# House Robberアルゴリズムで最大値を求める
prev, curr = 0, 0
for seg in segments:
    new_curr = max(curr, prev + seg)
    prev, curr = curr, new_curr

print(curr)
0