結果
| 問題 |
No.921 ずんだアロー
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:09:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 772 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 82,944 KB |
| 実行使用メモリ | 89,600 KB |
| 最終ジャッジ日時 | 2025-06-12 15:10:02 |
| 合計ジャッジ時間 | 2,670 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 5 |
ソースコード
n = int(input())
a = list(map(int, input().split()))
# Create blocks of consecutive same values
blocks = []
if not a:
print(0)
exit()
current_val = a[0]
current_len = 1
for num in a[1:]:
if num == current_val:
current_len += 1
else:
blocks.append(current_len)
current_val = num
current_len = 1
blocks.append(current_len)
# Dynamic programming to find maximum sum of non-adjacent blocks
if len(blocks) == 0:
print(0)
else:
prev0 = 0 # previous state: not taking the block
prev1 = blocks[0] # previous state: taking the block
for i in range(1, len(blocks)):
new_prev0 = max(prev0, prev1)
new_prev1 = prev0 + blocks[i]
prev0, prev1 = new_prev0, new_prev1
print(max(prev0, prev1))
gew1fw