結果

問題 No.1779 Magical Swap
ユーザー 👑 NachiaNachia
提出日時 2021-12-08 00:04:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,041 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 88,184 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-09-23 07:46:37
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 42 ms
7,940 KB
testcase_05 AC 18 ms
5,408 KB
testcase_06 AC 21 ms
5,304 KB
testcase_07 AC 36 ms
7,172 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 44 ms
7,972 KB
testcase_11 AC 24 ms
5,520 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 35 ms
7,136 KB
testcase_14 AC 43 ms
8,344 KB
testcase_15 AC 49 ms
4,380 KB
testcase_16 AC 42 ms
8,348 KB
testcase_17 AC 34 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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