結果
| 問題 |
No.3185 Three Abs
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-20 22:52:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 101 ms / 2,000 ms |
| コード長 | 1,041 bytes |
| コンパイル時間 | 3,447 ms |
| コンパイル使用メモリ | 253,844 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 22:52:42 |
| 合計ジャッジ時間 | 8,072 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template <typename T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <typename T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(15);
}
} io_setup;
#include <atcoder/all>
void solve() {
int n;
cin>>n;
vector<ll> a(n);
rep(i,0,n) cin>>a[i];
vector<ll> dp(6,0);
rep(i,0,n){
vector<ll> ndp(6,0);
ndp[0]=dp[0]+a[i];
ndp[1]=dp[1]-a[i];
ndp[2]=max({dp[0],dp[1],dp[2]})+a[i];
ndp[3]=max({dp[0],dp[1],dp[3]})-a[i];
ndp[4]=max({dp[2],dp[3],dp[4]})+a[i];
ndp[5]=max({dp[2],dp[3],dp[5]})-a[i];
swap(dp,ndp);
}
cout<<max(dp[4],dp[5])<<"\n";
}
int main() {
int t = 1;
cin >> t;
while (t--) solve();
}