結果

問題 No.1369 交換門松列・竹
ユーザー HaaHaa
提出日時 2021-01-29 22:10:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 175,616 KB
実行使用メモリ 6,464 KB
最終ジャッジ日時 2023-09-09 15:35:25
合計ジャッジ時間 3,301 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=1e18;

bool kad(int a, int b, int c){
    if(a==c)
        return 0;
    if(a>b&&b<c)
        return 1;
    if(a<b&&b>c)
        return 1;
    return 0;
}

int main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        VI a(n); REP(i,n) cin >> a[i];
        set<int> st;
        REP(i,n-2){
            if(!kad(a[i],a[i+1],a[i+2])){
                st.insert(i);
                st.insert(i+1);
                st.insert(i+2);
            }
        }
        VI nt;
        for(auto x:st) nt.push_back(x);
        int m=nt.size();
        if(m>15){
            cout << "No" << endl;
            continue;
        }
        bool no=1;
        REP(i,m){
            REP(j,i){
                swap(a[nt[i]],a[nt[j]]);
                bool ok=1;
                REP(k,n-2){
                    if(!kad(a[k],a[k+1],a[k+2])){
                        ok=0;
                        break;
                    }
                }
                if(ok){
                    cout << "Yes" << endl;
                    no=0;
                    break;
                }
                swap(a[nt[i]],a[nt[j]]);
            }
            if(!no)
                break;
        }
        if(no)
            cout << "No" << endl;
    }
    return 0;
}
0