結果
問題 |
No.921 ずんだアロー
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:36:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 860 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 94,976 KB |
最終ジャッジ日時 | 2025-04-16 00:40:48 |
合計ジャッジ時間 | 2,779 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 5 |
ソースコード
n = int(input()) a = list(map(int, input().split())) # Create groups of consecutive same values groups = [] if not a: print(0) exit() current_val = a[0] current_len = 1 for num in a[1:]: if num == current_val: current_len += 1 else: groups.append((current_val, current_len)) current_val = num current_len = 1 groups.append((current_val, current_len)) m = len(groups) dp = [0] * (m + 1) for i in range(1, m + 1): val, l = groups[i-1] option1 = dp[i-1] # Not choosing current group option2 = (dp[i-2] if i >= 2 else 0) + l # Choosing current group, previous not chosen option3 = 0 if i >= 2: prev_val, prev_l = groups[i-2] if prev_val == val: option3 = dp[i-1] + l # Previous group same value and chosen dp[i] = max(option1, option2, option3) print(dp[m])