/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 1ms 540.0 KiB
#3 Wrong Answer 40ms 796.0 KiB

Code

#define ll long long
#include <bits/stdc++.h>
using namespace std;

std::string toBinaryString(long long num) {
    std::bitset<64> binary(num);
    return binary.to_string();
}

long long binaryToLongLong(const std::string& binary) {
    std::bitset<64> binarySet(binary);
    return static_cast<long long>(binarySet.to_ullong());
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long t;
    cin >> t;
    while(t--){
        long long n;
        cin >> n;
        vector<ll> a(n), b(n);
        for(ll i = 0; i < n; i++) cin >> a[i];
        for(ll i = 0; i < n; i++) cin >> b[i];

        if(n <= 2){
            cout << "Yes\n";
            continue;
        }

        priority_queue<ll, vector<ll>, greater<ll>> aa, bb;
        for(ll i = 0; i < n; i++){
            aa.push(a[i]);
            bb.push(b[i]);
        }

        vector<ll> aaa(n, 0), bbb(n, 0);
        aaa[n - 1] = aa.top(); aa.pop();
        aaa[0]     = aa.top(); aa.pop();
        for(ll i = 1; i < n - 1; i++){
            aaa[i] = aa.top(); aa.pop();
        }
   

        int idx = 0;
        while(!bb.empty()){
            bbb[idx] = bb.top(); bb.pop();
            idx += 1;
        }

        bool yes = true;
        for(ll i = 1; i < n - 1; i++){
            if(!(aaa[i] <= bbb[i - 1] && aaa[i] <= bbb[i + 1]))
                yes = false;
        }

        if(yes){
            cout << "Yes\n";
            continue;
        }

        // try swapping roles
        while(!aa.empty()) aa.pop();
        while(!bb.empty()) bb.pop();
        for(ll i = 0; i < n; i++){
            aa.push(b[i]);
            bb.push(a[i]);
        }

        aaa.assign(n, 0);
        bbb.assign(n, 0);
            aaa[n - 1] = aa.top(); aa.pop();
        aaa[0]     = aa.top(); aa.pop();
        for(ll i = 1; i < n - 1; i++){
            aaa[i] = aa.top(); aa.pop();
        }
        
        idx = 0;
        while(!bb.empty()){
            bbb[idx] = bb.top(); bb.pop();
            idx += 1;
        }

        yes = true;
        for(ll i = 1; i < n - 1; i++){
            if(!(aaa[i] <= bbb[i - 1] && aaa[i] <= bbb[i + 1]))
                yes = false;
        }

        cout << (yes ? "Yes\n" : "No\n");
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1193 C. Roy and Peak Array
Contest
Brain Booster #10
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 16:55:49
Judged At
2025-06-13 16:55:49
Judged By
Score
0
Total Time
40ms
Peak Memory
796.0 KiB