結果

問題 No.1369 交換門松列・竹
ユーザー sister_DBsister_DB
提出日時 2021-02-28 20:15:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 76,944 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-12 10:14:00
合計ジャッジ時間 5,345 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
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 <iostream>
#include <vector>
#include <utility>
using namespace std;

bool isKadomatu(const vector<int>& v){
    for(int i = 1; i < v.size() - 1; ++i){
        if((v[i-1] < v[i] && v[i+1] < v[i]) || (v[i-1] > v[i] && v[i+1] > v[i])){
            continue;
        }else{
            return false;
        }
    }
    return true;
}

int main(){
    int t;
    cin >> t;
    
    for(int i = 0; i < t; ++i){
        int n;
        cin >> n;
        vector<int> v(n);
        for(int j = 0; j < n; ++j){
            cin >> v[j];
        }
        bool found = false;
        for(int j = 0; j < n-1; ++j){
            for(int k = j+1; k < n; ++k){
                swap(v[j], v[k]);
                if(isKadomatu(v)){
                    found = true;
                    break;
                }
                swap(v[j], v[k]);
            }
            if(!found){
                break;
            }
        }
        if(found){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    
    return 0;
}
0