結果

問題 No.1369 交換門松列・竹
ユーザー MisterMister
提出日時 2021-01-29 21:38:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 83,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 14:57:32
合計ジャッジ時間 2,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

bool judge(int a, int b, int c) {
    if (a == c) return false;
    return (a < b && b > c) ||
           (a > b && b < c);
}

bool judge_all(const vector<int>& xs) {
    int n = xs.size();
    for (int i = 0; i + 2 < n; ++i) {
        if (!judge(xs[i], xs[i + 1], xs[i + 2])) return false;
    }
    return true;
}

void solve() {
    int n;
    cin >> n;

    vector<int> xs(n);
    for (auto& x : xs) cin >> x;

    vector<int> is;
    for (int i = 0; i + 2 < n; ++i) {
        if (judge(xs[i], xs[i + 1], xs[i + 2])) continue;
        for (int j = 0; j < 3; ++j) is.push_back(i + j);
    }

    sort(is.begin(), is.end());
    is.erase(unique(is.begin(), is.end()), is.end());

    int m = is.size();
    if (m > 10) {
        cout << "No\n";
        return;
    }

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < i; ++j) {
            swap(xs[is[i]], xs[is[j]]);

            if (judge_all(xs)) {
                cout << "Yes\n";
                return;
            }

            swap(xs[is[i]], xs[is[j]]);
        }
    }

    cout << "No\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int q;
    cin >> q;
    while (q--) solve();

    return 0;
}
0