結果

問題 No.3185 Three Abs
ユーザー t98slider
提出日時 2025-06-20 22:02:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 3,761 ms
コンパイル使用メモリ 253,608 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 22:03:13
合計ジャッジ時間 8,326 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

void solve(){
    int n, v;
    cin >> n;
    array<ll, 6> dp;
    dp.fill(0);
    for(int i = 0; i < n; i++){
        array<ll, 6> ndp;
        ndp.fill(-(1ll << 62));
        cin >> v;
        for(int j = 0; j < 6; j++){
            if(j % 2 == 0){
                ndp[j] = max(ndp[j], dp[j] + v);
                for(int k = (j / 2) * 2 - 1; k >= 0; k--){
                    ndp[j] = max(ndp[j], dp[k] + v);
                }
            }else{
                ndp[j] = max(ndp[j], dp[j] - v);
                for(int k = (j / 2) * 2 - 1; k >= 0; k--){
                    ndp[j] = max(ndp[j], dp[k] - v);
                }
            }
        }
        dp = ndp;
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--) solve();
}
0