提出 #41126530


ソースコード 拡げる

#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
const double pi = 3.14159265359;
const ll INF = 1LL << 60;

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

//using mint = modint998244353;
//using mint = modint1000000007;
//using mint = modint;  // mint::set_mod(p); later
//using mint = static_modint<1000000009>;

int main()
{
  cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

  // Input
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (auto &&t : a){ cin >> t; t--; }
  for (auto &&t : b){ cin >> t; t--; }

  // 多重集合として一致するかをみる。
  vector<int> ca(N), cb(N);
  bool flg = false; // A の中に二回以上登場する要素がある
  for (int na : a){
    if (ca[na] != 0) flg = true;
    ca[na]++;
  }
  for (int nb : b){
    cb[nb]++;
  }
  for (int i = 0; i < N; i++){
    if (ca[i] != cb[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  if (flg){
    cout << "Yes" << endl;
    return 0;
  }

  // この時点で、A と B は何も [0, 1, ..., N-1] の並び替え

  // A, B それぞれの転倒数の合計を求める。
  fenwick_tree<int> c(N), d(N);
  ll z = 0;
  for (int na : a){
    z += c.sum(na, N);
    c.add(na, 1);
  }
  for (int nb : b){
    z += d.sum(nb, N);
    d.add(nb, 1);
  }


  cout << (z%2 == 0 ? "Yes" : "No") << endl;
  return 0;
}

提出情報

提出日時
問題 F - Simultaneous Swap
ユーザ unnohideyuki
言語 C++ (GCC 9.2.1)
得点 500
コード長 1623 Byte
結果 AC
実行時間 56 ms
メモリ 7972 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 4
AC × 48
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, overlap_00.txt, overlap_01.txt, overlap_02.txt, overlap_03.txt, overlap_04.txt, overlap_05.txt, overlap_06.txt, overlap_07.txt, overlap_08.txt, overlap_09.txt, overlap_10.txt, overlap_11.txt, overlap_12.txt, overlap_13.txt, overlap_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 8 ms 3676 KiB
example_01.txt AC 2 ms 3664 KiB
example_02.txt AC 2 ms 3676 KiB
example_03.txt AC 2 ms 3640 KiB
hand_00.txt AC 47 ms 7972 KiB
hand_01.txt AC 47 ms 7868 KiB
hand_02.txt AC 51 ms 7828 KiB
hand_03.txt AC 51 ms 7936 KiB
hand_04.txt AC 30 ms 6224 KiB
hand_05.txt AC 28 ms 6340 KiB
hand_06.txt AC 38 ms 6244 KiB
hand_07.txt AC 37 ms 6224 KiB
hand_08.txt AC 37 ms 6288 KiB
overlap_00.txt AC 39 ms 6392 KiB
overlap_01.txt AC 40 ms 6380 KiB
overlap_02.txt AC 41 ms 6296 KiB
overlap_03.txt AC 40 ms 6284 KiB
overlap_04.txt AC 40 ms 6300 KiB
overlap_05.txt AC 39 ms 6244 KiB
overlap_06.txt AC 40 ms 6380 KiB
overlap_07.txt AC 40 ms 6252 KiB
overlap_08.txt AC 40 ms 6244 KiB
overlap_09.txt AC 40 ms 6332 KiB
overlap_10.txt AC 40 ms 6216 KiB
overlap_11.txt AC 41 ms 6392 KiB
overlap_12.txt AC 40 ms 6328 KiB
overlap_13.txt AC 40 ms 6284 KiB
overlap_14.txt AC 39 ms 6248 KiB
random_00.txt AC 52 ms 7912 KiB
random_01.txt AC 52 ms 7808 KiB
random_02.txt AC 52 ms 7804 KiB
random_03.txt AC 51 ms 7916 KiB
random_04.txt AC 52 ms 7892 KiB
random_05.txt AC 52 ms 7832 KiB
random_06.txt AC 52 ms 7960 KiB
random_07.txt AC 52 ms 7764 KiB
random_08.txt AC 51 ms 7920 KiB
random_09.txt AC 56 ms 7948 KiB
random_10.txt AC 52 ms 7972 KiB
random_11.txt AC 52 ms 7804 KiB
random_12.txt AC 51 ms 7868 KiB
random_13.txt AC 51 ms 7972 KiB
random_14.txt AC 51 ms 7884 KiB
random_15.txt AC 52 ms 7948 KiB
random_16.txt AC 52 ms 7808 KiB
random_17.txt AC 53 ms 7912 KiB
random_18.txt AC 52 ms 7940 KiB
random_19.txt AC 50 ms 7916 KiB