/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 576.0 KiB
#2 Accepted 32ms 532.0 KiB
#3 Time Exceeded ≥2100ms ≥644.0 KiB
#4 Time Exceeded ≥2098ms ≥532.0 KiB

Code

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(auto &i: a) cin >> i;
    for(auto &i: b) cin >> i;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    auto check = [&](vector<int> vec1, vector<int> vec2) -> bool {
        for(int i = 2, j = 0; i < n; i++, j++) {
            if(vec1[i] > vec2[j] && vec1[i] > vec2[j + 2]) continue;
            return 0;
        }
        return 1;
    };
    if(check(a, b) or check(b, a)) {
        cout << "Yes" << endl;
        return;
    }
    
    auto check2 = [&](auto &v1, auto &v2) -> bool {
        for(int i = 1; i + 1 < n; i++) {
            if(v1[i] > v2[i - 1] && v1[i] > v2[i + 1]) continue;
            return 0;
        }
        return 1;
    };
    
    int t = 500;
    random_device rd; 
    while(t--) {
        mt19937 g(rd()); 
        shuffle(a.begin(), a.end(), g);

        mt19937 g1(rd());
        shuffle(b.begin(), b.end(), g1);

        if(check2(a, b) or check2(b, a)) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1193 C. Roy and Peak Array
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-01 18:13:30
Judged At
2025-06-01 18:13:30
Judged By
Score
5
Total Time
≥2100ms
Peak Memory
≥644.0 KiB