結果
| 問題 | 
                            No.921 ずんだアロー
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 15:13:48 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 943 bytes | 
| コンパイル時間 | 266 ms | 
| コンパイル使用メモリ | 82,808 KB | 
| 実行使用メモリ | 101,168 KB | 
| 最終ジャッジ日時 | 2025-06-12 15:14:00 | 
| 合計ジャッジ時間 | 2,786 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 15 WA * 7 | 
ソースコード
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()
            
            
            
        
            
gew1fw