結果

問題 No.1779 Magical Swap
ユーザー kyo1kyo1
提出日時 2021-12-09 13:26:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 205,092 KB
実行使用メモリ 4,988 KB
最終ジャッジ日時 2023-09-24 06:41:34
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 17 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 34 ms
4,724 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 26 ms
4,464 KB
testcase_14 AC 33 ms
4,988 KB
testcase_15 AC 24 ms
4,380 KB
testcase_16 AC 21 ms
4,380 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 1 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename T>
bool is_prime(T n) {
  if (n == 0 || n == 1) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (T i = 3; i * i < n + 1; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  auto solve = [&]() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (auto &&e : A) {
      cin >> e;
    }
    for (auto &&e : B) {
      cin >> e;
    }
    vector<int> X, Y;
    for (int i = 0; i < N; i++) {
      if (i == 0 || (is_prime(i + 1) && 2 * (i + 1) > N)) {
        if (A[i] != B[i]) {
          cout << "No" << '\n';
          return;
        }
      }
      X.emplace_back(A[i]);
      Y.emplace_back(B[i]);
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    cout << (X == Y ? "Yes" : "No") << '\n';
  };
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}
0