結果

問題 No.1779 Magical Swap
コンテスト
ユーザー 👑 Nachia
提出日時 2021-12-08 00:04:42
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.90.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,041 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,775 ms
コンパイル使用メモリ 89,236 KB
実行使用メモリ 8,504 KB
最終ジャッジ日時 2026-06-24 13:41:22
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/dsu>
using namespace std;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)


void testcase(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    vector<int> B(N);
    rep(i,N) cin >> B[i];
    atcoder::dsu G(N);
    for(int k=2; k<=N; k++) for(int i=2; k*i<=N; i++) G.merge(k-1,k*i-1);
    bool ok = true;
    for(auto& group : G.groups()){
        vector<int> tmpA;
        vector<int> tmpB;
        for(auto a : group){
            tmpA.push_back(A[a]);
            tmpB.push_back(B[a]);
        }
        sort(tmpA.begin(), tmpA.end());
        sort(tmpB.begin(), tmpB.end());
        if(tmpA != tmpB) ok = false;
    }
    if(ok) cout << "Yes\n";
    else cout << "No\n";
}


int main() {
    int T; cin >> T;
    while(T--) testcase();
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0