結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー ktr216ktr216
提出日時 2021-01-29 22:10:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 168,412 KB
実行使用メモリ 5,652 KB
最終ジャッジ日時 2023-09-09 15:35:34
合計ジャッジ時間 3,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 43 ms
4,376 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 63 ms
5,348 KB
testcase_06 AC 62 ms
5,520 KB
testcase_07 AC 61 ms
5,460 KB
testcase_08 AC 63 ms
5,312 KB
testcase_09 AC 47 ms
5,308 KB
testcase_10 AC 48 ms
5,512 KB
testcase_11 AC 47 ms
5,652 KB
testcase_12 AC 48 ms
5,456 KB
testcase_13 AC 47 ms
5,452 KB
testcase_14 AC 48 ms
5,440 KB
testcase_15 AC 49 ms
5,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
    }
}
0