結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-29 22:10:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 1,578 ms |
| コンパイル使用メモリ | 169,300 KB |
| 実行使用メモリ | 5,608 KB |
| 最終ジャッジ日時 | 2024-06-27 08:24:17 |
| 合計ジャッジ時間 | 2,971 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
int T;
cin >> T;
while (T-- > 0) {
int N;
cin >> N;
vector<int> A(N + 2);
rep(i, N) cin >> A[i];
A[N] = A[0];
A[N + 1] = A[1];
ll ans = 0;
rep(i, 3) {
vector<ll> dp(N + 1, 0);
rep (j, N) {
dp[j + 1] = max(dp[j + 1], dp[j]);
if (j < N - 2 && 1LL * (A[j + i] - A[j + i + 1]) * (A[j + i + 1] - A[j + i + 2]) < 0 && A[j + i] != A[j + i + 2]) {
dp[j + 3] = max(dp[j + 3], dp[j] + A[j + i]);
}
}
//rep(j, N + 1) cout << dp[j] << " "; cout << "\n";
ans = max(ans, dp[N]);
}
cout << ans << "\n";
}
}