結果

問題 No.921 ずんだアロー
ユーザー lam6er
提出日時 2025-04-16 00:36:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 652 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 89,984 KB
最終ジャッジ日時 2025-04-16 00:40:47
合計ジャッジ時間 2,740 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if n == 0:
    print(0)
    exit()

# Segment the array into blocks of consecutive same values
blocks = []
current_val = a[0]
current_length = 1
for num in a[1:]:
    if num == current_val:
        current_length += 1
    else:
        blocks.append(current_length)
        current_val = num
        current_length = 1
blocks.append(current_length)

# Apply dynamic programming similar to the House Robber problem
prev_no = 0
prev_yes = 0
for length in blocks:
    new_no = max(prev_no, prev_yes)
    new_yes = prev_no + length
    prev_no, prev_yes = new_no, new_yes

print(max(prev_no, prev_yes))
0