結果

問題 No.1707 Simple Range Reverse Problem
ユーザー simansiman
提出日時 2021-10-16 11:24:40
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 2,022 ms
コンパイル使用メモリ 131,696 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:07:08
合計ジャッジ時間 2,911 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 3 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 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

void solver(int N, vector<int> &A) {
  if (A[0] != 1) {
    cout << "No" << endl;
    return;
  }

  for (int i = 1; i < 2 * N; ++i) {
    int x = i % N + 1;
    if (A[i] == x) continue;
    int from = i - 1;
    int y = A[from];
    int j = i;
    while (j < 2 * N && A[j] != y) {
      ++j;
    }
    // fprintf(stderr, "%d: swap: (%d, %d)\n", x, i, j);
    if (j >= 2 * N) {
      cout << "No" << endl;
      return;
    }
    reverse(A.begin() + from, A.begin() + j + 1);
    if (A[i] != x) {
      cout << "No" << endl;
      return;
    }
    /*
    for (int v : A) {
      cout << v << " ";
    }
    cout << endl;
    */
  }

  cout << "Yes" << endl;
}

int main() {
  int T;
  cin >> T;

  for (int i = 0; i < T; ++i) {
    int N;
    cin >> N;
    vector<int> A(2 * N);

    for (int j = 0; j < 2 * N; ++j) {
      cin >> A[j];
    }

    solver(N, A);
  }

  return 0;
}
0