結果

問題 No.1369 交換門松列・竹
ユーザー carrot46carrot46
提出日時 2021-01-29 22:02:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,350 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 172,228 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 15:25:44
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

bool judge(vec &a, int l){
    if(l < 0 || l + 2 >= N) return true;
    return a[l] != a[l + 2] && ((a[l] < a[l + 1] && a[l + 1] > a[l + 2]) || (a[l] > a[l + 1] && a[l + 1] < a[l + 2]));
}

bool judge_plus(vec &a, int p, int q, vec &id){
    bool res = true;
    reps(i, p - 1, p + 2) res &= judge(a, i);
    reps(i, q - 1, q + 2) res &= judge(a, i);
    for(int r : id){
        reps(i, r - 1, r + 2) res &= judge(a, i);
    }
    return res;
}

void solve(vec &a, vec &id){
    int n = id.size();
    rep(tempi, n){
        rep(tempj, tempi){
            int i = id[tempi], j = id[tempj];
            swap(a[i], a[j]);
            if(judge_plus(a, i, j, id)){
                cout<<"Yes"<<endl;
                return;
            }
            swap(a[i], a[j]);
        }
    }
    cout<<"No"<<endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>Q;
    rep(_, Q){
        cin>>N;
        vec a(N), can_change_masu(N + 1, 0), id(0);
        rep(i, N) cin>>a[i];
        rep(i, N - 2){
            if(!judge(a, i)){
                can_change_masu[i] += 1;
                can_change_masu[i + 3] -= 1;
            }
        }
        rep(i, N) {
            if(can_change_masu[i] > 0){
                id.push_back(i);
            }
            can_change_masu[i+1] += can_change_masu[i];
        }
        if(id.size() < 10){
            solve(a, id);
        }else{
            cout<<"No"<<endl;
        }
    }
}
0