結果

問題 No.1369 交換門松列・竹
ユーザー auauaauaua
提出日時 2021-01-30 18:31:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,210 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 175,632 KB
実行使用メモリ 5,772 KB
最終ジャッジ日時 2023-09-10 15:01:55
合計ジャッジ時間 3,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll mod=998244353;
const ll MAX=100010;

bool is_k(ll a, ll b,ll c){
    bool f=0;
    if((a>b&&c>b)||(a<b&&c<b))f=1;
    if(a==b||c==b||c==a)f=0;
    return f;
}

signed main(){
    ll t;cin>>t;
    while(t--){
        ll n;cin>>n;
        vector<ll>a(n);
        rep(i,n)cin>>a[i];
        set<ll>st;
        REP(i,2,n){
            if(!is_k(a[i-2],a[i-1],a[i])){
                st.insert(i);
                st.insert(i-1);
                st.insert(i-2);
            }
        }
        if(st.size()>=20){
            cout<<"No"<<endl;
            continue;
        }
        vector<ll>b(0);
        for(auto e:st){
            b.pb(e);
        }
        bool f=0;
        rep(i,b.size()){
            REP(j,i+1,b.size()){
                vector<ll>c=a;
                swap(c[b[i]],c[b[j]]);
                bool g=1;
                REP(k,2,n){
                    if(!is_k(c[k],c[k-1],c[k-2]))g=0;
                }
                f|=g;
            }
        }
        if(b.size()<=4){
            rep(i,b.size()){
                rep(j,n){
                    if(a[b[i]]==a[j])continue;
                    swap(a[b[i]],a[j]);
                    bool g=1;
                    rep(k,3){
                        if(b[i]-2+k>=0&&b[i]+k<n){
                            if(!is_k(a[b[i]-2+k],a[b[i]-1+k],a[b[i]+k]))g=0;
                        }
                        if(j-2+k>=0&&j+k<n){
                            if(!is_k(a[j-2+k],a[j-1+k],a[j+k]))g=0;
                        }
                    }
                    f|=g;
                    swap(a[b[i]],a[j]);
                }
            }
        }
        cout<<(f?"Yes":"No")<<endl;
    }
}
0