結果

問題 No.1707 Simple Range Reverse Problem
ユーザー たこしたこし
提出日時 2021-10-15 21:46:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,601 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 203,184 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 20:11:49
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 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 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 long

using 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;
}
0