結果
問題 | No.1707 Simple Range Reverse Problem |
ユーザー |
![]() |
提出日時 | 2021-10-15 21:46:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,601 bytes |
コンパイル時間 | 2,075 ms |
コンパイル使用メモリ | 193,288 KB |
最終ジャッジ日時 | 2025-01-25 00:43:26 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define INF 100000000#define YJ 1145141919#define INF_INT_MAX 2147483647#define INF_LL 9223372036854775#define INF_LL_MAX 9223372036854775807#define EPS 1e-10#define MOD 1000000007#define MOD9 998244353#define Pi acos(-1)#define LL long long#define ULL unsigned long long#define LD long double#define int long longusing II = pair<int, int>;int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }int lcm(int a, int b) { return a * b / gcd(a, b); }int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define ALL(a) begin((a)), end((a))#define RALL(a) (a).rbegin(), (a).rend()#define PB push_back#define MP make_pair#define SZ(a) int((a).size())const int MAX_N = 2001;int A[MAX_N];int N;signed main() {int T;cin >> T;REP(test_case, T) {cin >> N;REP(n, 2*N) {cin >> A[n]; A[n]--;}if (A[0] != 0 || A[2*N-1] != N-1) {cout << "No" << endl;continue;}bool failed_flag = false;FOR(n, 1, N) {if (A[n] != n%N) {int index = -1;FOR(k, n+1, 2*N) {if (A[k] == A[n-1]) {index = k;break;}}if (index == -1) {continue;}reverse(A+n-1, A+index+1);}}// REP(nn, 2*N) {// cerr << A[nn] << " ";// }// cerr << endl;reverse(A, A+2*N);FOR(n, 1, N) {if (A[n] != N-1-n) {int index = -1;FOR(k, n+1, 2*N) {if (A[k] == A[n-1]) {index = k;break;}}if (index == -1) {continue;}reverse(A+n-1, A+index+1);}}reverse(A, A+2*N);// REP(nn, 2*N) {// cerr << A[nn] << " ";// }// cerr << endl;REP(n, 2*N) {if (A[n] != n%N) {failed_flag = true;}}if (failed_flag) {cout << "No" << endl;continue;} else {cout << "Yes" << endl;}}return 0;}