結果

問題 No.921 ずんだアロー
ユーザー gew1fw
提出日時 2025-06-12 20:03:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 100,640 KB
最終ジャッジ日時 2025-06-12 20:08:40
合計ジャッジ時間 2,943 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    
    # Calculate maximum frequency of any number
    freq = defaultdict(int)
    for num in a:
        freq[num] += 1
    max_freq = max(freq.values()) if freq else 0
    
    # Calculate maximum non-adjacent count using dynamic programming
    if n == 0:
        max_non_adjacent = 0
    else:
        prev_no = 0  # previous state: not taking the previous element
        prev_yes = 1  # previous state: taking the previous element
        for i in range(1, n):
            current_no = max(prev_no, prev_yes)
            current_yes = prev_no + 1
            prev_no, prev_yes = current_no, current_yes
        max_non_adjacent = max(prev_no, prev_yes)
    
    # The answer is the maximum of the two values
    print(max(max_freq, max_non_adjacent))

if __name__ == "__main__":
    main()
0