結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー boutarouboutarou
提出日時 2021-01-29 21:50:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 3,593 ms
コンパイル使用メモリ 201,684 KB
実行使用メモリ 8,556 KB
最終ジャッジ日時 2023-09-09 15:13:55
合計ジャッジ時間 3,844 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
using ll = long long;
using P = pair<ll, ll>;

bool kadomatsu(ll a, ll b, ll c) {
    if (a != b && b != c && c != a && (max({a, b, c}) == b || min({a, b, c}) == b)) return true;
    return false;
}
void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, 3) {
        vector<ll> b;
        rep(j, n) {
            b.push_back(a[(i + j) % n]);
        }
        vector<ll> dp(n + 1);
        rep(i, n - 2) {
            if (kadomatsu(b[i], b[i + 1], b[i + 2])) {
                dp[i + 3] = max(dp[i + 3], dp[i] + b[i]);
            }
        }
        cout << dp[n] << endl;
    }
}

int main() {
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
0