結果

問題 No.1779 Magical Swap
ユーザー 蜜蜂蜜蜂
提出日時 2021-12-08 00:47:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 3,985 ms
コンパイル使用メモリ 238,260 KB
実行使用メモリ 11,932 KB
最終ジャッジ日時 2023-09-23 07:48:15
合計ジャッジ時間 5,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 30 ms
7,252 KB
testcase_05 AC 14 ms
5,120 KB
testcase_06 AC 15 ms
5,116 KB
testcase_07 AC 26 ms
6,572 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 22 ms
5,032 KB
testcase_10 AC 101 ms
11,080 KB
testcase_11 AC 48 ms
7,208 KB
testcase_12 AC 15 ms
4,480 KB
testcase_13 AC 75 ms
9,176 KB
testcase_14 AC 108 ms
11,932 KB
testcase_15 AC 63 ms
4,500 KB
testcase_16 AC 36 ms
8,012 KB
testcase_17 AC 51 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

void solve(){
  int n;
  cin>>n;

  vi a(n+1,0),b(n+1,0);
  rep(i,1,n+1){
    cin>>a[i];
  }
  rep(i,1,n+1){
    cin>>b[i];
  }

  dsu d(n+1);
  rep(k,2,n+1){
    rep(i,2,n+1){
      if(k*i>n){
        break;
      }
      if(d.same(k,k*i)==false){
        d.merge(k,k*i);
      }
    }
  }

  auto g=d.groups();

  for(auto x:g){
    map<int,int> cnt;
    for(auto v:x){
      cnt[a[v]]++;
    }
    for(auto v:x){
      if(cnt[b[v]]<=0){
        cout<<"No\n";
        return;
      }
      cnt[b[v]]--;
    }
  }

  cout<<"Yes\n";
}

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

  int t;
  cin>>t;

  while(t--){
    solve();
  }
}
0