結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー mmn15277198mmn15277198
提出日時 2021-01-30 18:42:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 74,596 KB
実行使用メモリ 4,932 KB
最終ジャッジ日時 2023-09-10 15:15:15
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 39 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 59 ms
4,660 KB
testcase_06 WA -
testcase_07 AC 60 ms
4,880 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 <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int f(int a , int b , int c){
    if(a == b || b == c || c == a){
        return 0;
    }
    if(b < a && b < c){
        return a;
    }
    if(b > a && b > c){
        return a;
    }
    return 0;
}

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a.push_back(a[0]);
    a.push_back(a[1]);
    long long res = 0;
    long long cost0 = 0 , cost1 = 0 , cost2 = 0;
    for (int i = 0; i < n; i++) {
        if(i % 3 == 0)cost0 += f(a[i] , a[i + 1] , a[i + 2]);
        if(i % 3 == 1)cost1 += f(a[i] , a[i + 1] , a[i + 2]);
        if(i % 3 == 2)cost2 += f(a[i] , a[i + 1] , a[i + 2]);
    }
    res = max({cost0 , cost1 , cost2});
    cout << res << endl;
}
int main() {
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0