結果

問題 No.1369 交換門松列・竹
ユーザー boutarouboutarou
提出日時 2021-01-29 22:14:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,167 bytes
コンパイル時間 2,404 ms
コンパイル使用メモリ 203,492 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-09 15:40:30
合計ジャッジ時間 3,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 21 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 18 ms
4,384 KB
testcase_23 WA -
testcase_24 AC 14 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 15 ms
4,384 KB
testcase_31 AC 14 ms
4,380 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool kadomatsu(vector<int> a) {
    int n = a.size();
    rep(i, n - 2) {
        if ((a[i] < a[i + 1] && a[i + 1] < a[i + 2]) || (a[i] > a[i + 1] && a[i + 1] > a[i + 2])) {
            return false;
        }
    } 
    return true;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> x;
    rep(i, n - 2) {
        if ((a[i] < a[i + 1] && a[i + 1] < a[i + 2]) || (a[i] > a[i + 1] && a[i + 1] > a[i + 2])) {
            x.push_back(a[i]);
            x.push_back(a[i + 1]);
            x.push_back(a[i + 2]);
        }
    }
    if ((int)x.size() > 20) {
        cout << "No" << endl;
        return;
    }
    rep(i, x.size()) {
        rep(j, x.size()) {
            swap(a[i], a[j]);
            if (kadomatsu(a)) {
                cout << "Yes" << endl;
                return;
            }
            swap(a[i], a[j]);
        }
    }
    cout << "No" << endl;
}

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