結果

問題 No.1707 Simple Range Reverse Problem
ユーザー chineristACchineristAC
提出日時 2021-09-17 21:18:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,022 bytes
コンパイル時間 5,226 ms
コンパイル使用メモリ 219,520 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 19:55:58
合計ジャッジ時間 5,995 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
//include "testlib.h"
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using mint = modint1000000007;

#define rep(i,n,c) for (int i=0;i<n;i+=c)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x,int s=20){
  int cnt = 0;
  for (auto e:x){
    cnt += 1;
    cout<<e<<" ";
    if (cnt >= s){
      break;
    }
  }
  cout<<"\n";
}

bool solve(int n,vec<int> A){
  bool no_ope = true;
  for (int i=0;i<n;i++){
    if (A[i]!=i+1 || A[i+n]!=i+1){
      no_ope = false;
    }
  }
  if (no_ope){
    return true;
  }

  for (int i=0;i<n;i++){
    vec<int> X(2*n);
    for (int j=0;j<n;j++){
      X[j] = j + 1;
      X[j+n] = j + 1;
    }
    for (int j=i;j<=2*i+n-j;j++){
      swap(X[j],X[2*i+n-j]);
    }
    if (X==A){
      return true;
    }
  }
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int T;
  cin>>T;

  while (T--)  {
    int n;
    cin>>n;
    vec<int> A(2*n);
    for (int i=0;i<2*n;i++){
      cin>>A[i];
    }
    bool res = solve(n,A);
    if (res){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}

0