結果

問題 No.1707 Simple Range Reverse Problem
ユーザー asaringoasaringo
提出日時 2022-05-29 18:56:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 2,744 ms
コンパイル使用メモリ 206,828 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 00:07:58
合計ジャッジ時間 3,391 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<bool,ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

int t ;

void solve(){
    int n;
    cin >> n;
    vector<vector<int>> vec(n+1) ;
    vector<int> A(2*n) , S(2*n) ;
    rep(i,2*n) {
        S[i] = i % n + 1 ;
        cin >> A[i] ;
        vec[A[i]].push_back(i) ;
    }
    rrep(i,1,n+1) if(vec[i].size() != 2){
        cout << "No" << endl ;
        return ;
    }
    bool ok = true ;
    rep(i,2*n){
        if(S[i] != A[i]) ok = false ;
    }
    if(ok){
        cout << "Yes" << endl ;
        return ;
    }
    bool res = false ;
    rrep(i,1,n+1){
        bool check = true ;
        vector<int> V(2*n) ;
        int l = vec[i][0] , r = vec[i][1] ;
        int s = l + 1 , t = r - 1 ;
        int v = t - s + 1 ;
        rep(j,2*n){
            if(s <= j && j <= t) V[j] = A[2*s+v-1-j] ;
            else V[j] = A[j] ;
        }
        rep(j,2*n) if(V[j] != S[j]) check = false ;
        if(check) res = true ;
    }
    if(res) cout << "Yes" << endl ;
    else cout << "No" << endl ;
}

int main(){
    cin >> t ;
    rep(i,t) solve() ;
}
0