結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー rogi52rogi52
提出日時 2022-10-04 00:54:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 204,848 KB
実行使用メモリ 5,916 KB
最終ジャッジ日時 2023-08-27 22:20:32
合計ジャッジ時間 4,149 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 25 ms
5,676 KB
testcase_08 RE -
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>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int T; cin >> T;
    rep(_,T) {
        int N; cin >> N;
        vector<int> A(N);
        rep(i,N) cin >> A[i];

        auto f = [N](vector<int> A) {
            vector<int> dp(N + 1, 0);
            rep(i,N) {
                // A[i], A[i + 1], A[i + 2]
                auto [mi, ma] = minmax({A[i], A[i + 1], A[i + 2]});
                if(A[i] != A[i + 1] && A[i + 1] != A[i + 2] && A[i + 2] != A[i] && (mi == A[i + 1] || ma == A[i + 2])) {
                    dp[i + 3] = max(dp[i + 3], dp[i] + A[i]);
                }
            }
            return *max_element(dp.begin(), dp.end());
        };

        int ans = 0;
        rep(_,3) {
            ans = max(ans, f(A));
            vector<int> nt;
            nt.push_back(A.back());
            rep(i,N-1) nt.push_back(A[i]);
            swap(A, nt);
        }

        cout << ans << "\n";
    }
}
0