結果
| 問題 |
No.1779 Magical Swap
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2021-12-08 10:04:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 181 ms / 2,000 ms |
| コード長 | 1,019 bytes |
| コンパイル時間 | 1,863 ms |
| コンパイル使用メモリ | 173,892 KB |
| 実行使用メモリ | 12,928 KB |
| 最終ジャッジ日時 | 2024-07-16 07:40:00 |
| 合計ジャッジ時間 | 3,964 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
int main(){
int t;
cin >> t;
int MAX_N = 100001;
vector<bool> PNJudge(MAX_N,true);
PNJudge[1] = false;
for(int i=2;i<MAX_N;i++){
if(!PNJudge[i]) continue;
for(int j=i*2;j<MAX_N;j+=i) PNJudge[j] = false;
}
rep(dark_hourensou,t){
int n;
cin >> n;
vector<int> a(n), b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
bool ans = (a[0]==b[0]);
multiset<int> as, bs;
rep(i,n){
if(!ans) break;
if(!i) continue;
if(PNJudge[i+1] && (i+1)*2 > n) ans = (a[i] == b[i]);
else{
as.insert(a[i]);
bs.insert(b[i]);
}
}
if(ans) ans = (as == bs);
if(ans) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
houren