結果

問題 No.1369 交換門松列・竹
ユーザー HaaHaa
提出日時 2021-01-29 22:24:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,768 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 175,976 KB
実行使用メモリ 6,532 KB
最終ジャッジ日時 2023-09-09 15:53:23
合計ジャッジ時間 3,381 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 16 ms
4,384 KB
testcase_16 AC 16 ms
4,376 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 17 ms
4,380 KB
testcase_20 AC 21 ms
4,380 KB
testcase_21 AC 16 ms
4,376 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 16 ms
4,376 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 10 ms
4,380 KB
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 41 ms
6,532 KB
testcase_31 AC 41 ms
6,368 KB
testcase_32 AC 5 ms
4,376 KB
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;
        }
        else if(m>5){
            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;
        }
        else{
            bool no=1;
            for(auto i:nt){
                REP(j,n){
                    swap(a[i],a[j]);
                    bool ok=1;
                    for(auto k:nt){
                        for(int l=max(0,(int)k-2);l<=min(n-3,(int)k);l++){
                            if(!kad(a[l],a[l+1],a[l+2])){
                                ok=0;
                                break;
                            }
                        }
                        if(!ok)
                            break;
                    }
                    for(int l=max(0,j-2);l<=min(n-3,j);l++){
                        if(!kad(a[l],a[l+1],a[l+2])){
                            ok=0;
                            break;
                        }
                    }
                    if(ok){
                        cout << "Yes" << endl;
                        no=0;
                        break;
                    }
                    swap(a[i],a[j]);
                }
                if(!no)
                    break;
            }
            if(no)
                cout << "No" << endl;
        }
    }
    return 0;
}
0