結果
| 問題 |
No.921 ずんだアロー
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:33:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 927 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 82,540 KB |
| 実行使用メモリ | 111,108 KB |
| 最終ジャッジ日時 | 2025-03-31 17:34:36 |
| 合計ジャッジ時間 | 3,002 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 7 |
ソースコード
n = int(input())
if n == 0:
print(0)
exit()
a = list(map(int, input().split()))
# Step 1: Split into groups of consecutive same values
groups = []
current_val = a[0]
current_count = 1
for num in a[1:]:
if num == current_val:
current_count += 1
else:
groups.append((current_val, current_count))
current_val = num
current_count = 1
groups.append((current_val, current_count))
# Step 2: Calculate same_max
from collections import defaultdict
value_sum = defaultdict(int)
for val, cnt in groups:
value_sum[val] += cnt
same_max = max(value_sum.values()) if value_sum else 0
# Step 3: Calculate indep_max using dynamic programming
prev_no = 0
prev_yes = 0
for num in a:
current_no = max(prev_no, prev_yes)
current_yes = prev_no + 1
prev_no, prev_yes = current_no, current_yes
indep_max = max(prev_no, prev_yes)
# Determine the result
print(max(same_max, indep_max))
lam6er