結果
問題 |
No.921 ずんだアロー
|
ユーザー |
![]() |
提出日時 | 2025-06-12 20:04:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 813 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 82,004 KB |
実行使用メモリ | 100,992 KB |
最終ジャッジ日時 | 2025-06-12 20:09:47 |
合計ジャッジ時間 | 2,480 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 7 |
ソースコード
n = int(input()) a = list(map(int, input().split())) # Calculate max_same from collections import defaultdict max_same = 0 current_val = None current_length = 0 count = defaultdict(int) for num in a: if num == current_val: current_length += 1 else: if current_val is not None: count[current_val] += current_length current_val = num current_length = 1 # Add the last segment if current_val is not None: count[current_val] += current_length if count: max_same = max(count.values()) else: max_same = 0 # Calculate max_non_adjacent using House Robber approach prev1, prev2 = 0, 0 for _ in a: current = max(prev1, prev2 + 1) prev2, prev1 = prev1, current max_non_adjacent = prev1 # Determine the answer print(max(max_same, max_non_adjacent))