結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー rogi52rogi52
提出日時 2022-10-04 00:56:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,162 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 205,344 KB
実行使用メモリ 5,920 KB
最終ジャッジ日時 2023-08-27 22:22:17
合計ジャッジ時間 3,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 27 ms
5,672 KB
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>
#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) {
                if(i + 2 < 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]);
                    }
                }
                dp[i + 1] = max(dp[i + 1], dp[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