結果
問題 |
No.3185 Three Abs
|
ユーザー |
![]() |
提出日時 | 2025-06-21 03:55:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,587 bytes |
コンパイル時間 | 461 ms |
コンパイル使用メモリ | 82,628 KB |
実行使用メモリ | 124,616 KB |
最終ジャッジ日時 | 2025-06-21 03:55:41 |
合計ジャッジ時間 | 22,661 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 30 |
ソースコード
from collections.abc import Iterable from enum import IntEnum, auto from functools import cache class E(IntEnum): S = 0 LP = auto() LN = auto() MP = auto() MN = auto() RP = auto() RN = auto() def nexts(self): match self: case E.S: return [E.LP, E.LN] case E.LP: return [E.LP, E.MP, E.MN] case E.LN: return [E.LN, E.MP, E.MN] case E.MP: return [E.MP, E.RP, E.RN] case E.MN: return [E.MN, E.RP, E.RN] case E.RP: return [E.RP] case E.RN: return [E.RN] assert False @staticmethod @cache def states(): res = [] for fm in E: for to in fm.nexts(): res.append((fm, to)) return res def state_dp(xs: Iterable, op, e, init: dict): dp = [e] * len(E) for k, v in init.items(): dp[k] = v for x in xs: pp = [e] * len(E) dp, pp = pp, dp for fm, to in E.states(): if not is_valid(to, pp[fm], x): continue dp[to] = op(to, dp[to], fm, pp[fm], x) return dp def is_valid(to: E, fm_v, v) -> bool: return True def get_value(to: E, fm_v, v): if to in (E.LN, E.MN, E.RN): return fm_v - v return fm_v + v def op(to: E, to_v, fm: E, fm_v, v): return max(to_v, get_value(to, fm_v, v)) def solve(): N = int(input()) A = list(map(int, input().split())) dp = state_dp(A, op, 0, {E.S: 0}) return max(dp[E.RP], dp[E.RN]) T = int(input()) for _ in range(T): ans = solve() print(ans)