結果

問題 No.1779 Magical Swap
ユーザー maguromaguro
提出日時 2021-12-09 11:13:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,836 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 207,440 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 04:18:02
合計ジャッジ時間 4,627 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 70 ms
4,376 KB
testcase_05 AC 31 ms
4,376 KB
testcase_06 AC 35 ms
4,380 KB
testcase_07 AC 58 ms
4,384 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 74 ms
4,376 KB
testcase_11 AC 40 ms
4,380 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 58 ms
4,380 KB
testcase_14 AC 61 ms
4,380 KB
testcase_15 AC 168 ms
4,380 KB
testcase_16 AC 77 ms
4,376 KB
testcase_17 AC 72 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
constexpr int Inf = 2000000000;
constexpr long long INF= 2000000000000000000;

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T,typename U>
T modpow(T N, U P, T M = -1) {
    if(P < 0) return 0;
    T ret = 1;
    if(M != -1) ret %= M;
    while(P) {
        if(P & 1) {
            if(M == -1) ret *= N;
            else ret = ret * N % M;
        }
        P /= 2;
        if(M == -1) N *= N;
        else N = N * N % M;
    }
    return ret;
}

constexpr long long MOD = 1000000007;

int main() {
    vector<bool> is_prime(100001,true);
    vector<int> prime;
    is_prime[0] = false;
    is_prime[1] = false;
    for(int i = 2;i < 100001;i++) {
        if(is_prime[i]) {
            prime.push_back(i);
            for(int j = 2;j <= 100000 / i;j++) {
                is_prime[i * j] = false;
            }
        }
    }

    int t;
    cin >> t;
    for(int tmp = 0;tmp < t;tmp++) {
        int n;
        cin >> n;
        vector<int> a(n);
        vector<int> b(n);
        for(auto& x: a) cin >> x;
        for(auto& x: b) cin >> x;
        bool ret = true;
        int itr = upper_bound(prime.begin(),prime.end(),n / 2) - prime.begin();
        int itr2 = upper_bound(prime.begin(),prime.end(),n) - prime.begin();
        if(a[0] != b[0]) ret = false;
        for(int i = itr;i < itr2;i++) {
            if(a[prime[i] - 1] != b[prime[i] - 1]) ret = false;
        }

        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        for(int i = 0;i < n;i++) {
            if(a[i] != b[i]) ret = false;
        }

        if(ret) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
0