結果
| 問題 |
No.921 ずんだアロー
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:34:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 652 bytes |
| コンパイル時間 | 153 ms |
| コンパイル使用メモリ | 81,884 KB |
| 実行使用メモリ | 90,752 KB |
| 最終ジャッジ日時 | 2025-04-16 00:35:54 |
| 合計ジャッジ時間 | 2,137 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 5 |
ソースコード
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))
lam6er