結果

問題 No.1369 交換門松列・竹
ユーザー boutarouboutarou
提出日時 2021-01-29 22:19:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,261 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 204,312 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-09 15:47:48
合計ジャッジ時間 5,879 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(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;
}

bool kadomatsu(vector<int> a) {
    int n = a.size();
    rep(i, n - 2) {
        if (!kadomatsu(a[i], 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(i);
            x.push_back(i + 1);
            x.push_back(i + 2);
        }
    }
    if ((int)x.size() > 6) {
        cout << "No" << endl;
        return;
    }
    rep(i, x.size()) {
        rep(j, n) {
            swap(a[x[i]], a[j]);
            if (kadomatsu(a)) {
                cout << "Yes" << endl;
                return;
            }
            swap(a[x[i]], a[j]);
        }
    }
    cout << "No" << endl;
}

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