結果
| 問題 | No.921 ずんだアロー |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:33:51 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 927 bytes |
| 記録 | |
| コンパイル時間 | 226 ms |
| コンパイル使用メモリ | 96,348 KB |
| 実行使用メモリ | 107,728 KB |
| 最終ジャッジ日時 | 2026-07-08 04:34:14 |
| 合計ジャッジ時間 | 4,320 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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