結果

問題 No.1779 Magical Swap
ユーザー hourenhouren
提出日時 2021-12-08 10:04:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 171,572 KB
実行使用メモリ 12,924 KB
最終ジャッジ日時 2023-09-23 07:49:31
合計ジャッジ時間 3,781 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 64 ms
4,380 KB
testcase_05 AC 29 ms
4,380 KB
testcase_06 AC 32 ms
4,384 KB
testcase_07 AC 55 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 31 ms
5,564 KB
testcase_10 AC 148 ms
11,740 KB
testcase_11 AC 66 ms
7,520 KB
testcase_12 AC 21 ms
4,972 KB
testcase_13 AC 104 ms
9,892 KB
testcase_14 AC 150 ms
12,924 KB
testcase_15 AC 189 ms
4,380 KB
testcase_16 AC 76 ms
4,380 KB
testcase_17 AC 91 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0