結果
問題 | No.1779 Magical Swap |
ユーザー |
👑 ![]() |
提出日時 | 2021-12-08 00:04:42 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 1,041 bytes |
コンパイル時間 | 3,408 ms |
コンパイル使用メモリ | 117,900 KB |
最終ジャッジ日時 | 2025-01-26 06:39:36 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#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;