/ 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 28ms 776.0 KiB

Code

/*
 *Copyright (c) Swadheen Islam Robi (SIR01)
 *Created on Fri Jun 13 2025 8:30:16 PM
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);

// void sir1()
// {
//     ll n; cin>>n;
//     ll x = sqrt(n);
//     ll ans = 0;
//     for(ll i =1; i<=x; i++)
//     {
//         ll j = i+1;
//         if(i*i<=n) ans++;
//         if(i*j<=n) ans++;
//     }
//     cout<<ans<<endl;
    
// }
// void sir2()
// {
//     ll a,b,c; cin>>a>>b>>c;
//     ll cnt = 0;
//     ll ans;
//     if(a%2)cnt++;
//     if(b%2)cnt++;
//     if(c%2)cnt++;
//     if(cnt<2) ans = a+b+c;
//     else if(cnt==2) ans = (a+b+c)-1;
//     else ans = (a+b+c)-2;
//     cout<<ans<<endl;

// }
bool val(const vector<ll>&A,const vector<ll>&B,ll n){
    for(ll i=1;i<n-1; i++){
        if(!((A[i]>B[i-1] && A[i]>B[i+1]) || (B[i]>A[i-1] && B[i]>A[i+1])))
            return false;
    }
    return true;
}


void sir3() {
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    for (auto &e : a) cin >> e;
    for (auto &d : b) cin >> d;

    if (n <= 2) {
        yes;
        return;
    }

    vector<ll> A1 = a, B1 = b;
    rsrt(A1); srt(B1);
    // ll tem = A1[0];
    // A1[0] = A1[n-1];
    // for(ll i=1; i<n; i++)
    // {
    //     ll tt = A1[i];
    //     A1[i] = tem;
    //     tem = tt;
    // }
    // for(ll i=0; i<n; i++) cout<<A1[i]<<" ";cout<<endl;
    // for(ll i=0; i<n; i++) cout<<B1[i]<<" ";cout<<endl;
    if (val(A1, B1, n)) {
        yes;
        return;
    }

    vector<ll> A2 = a, B2 = b;
    srt(A2); rsrt(B2);
    
    // tem = B2[0];
    // B2[0] = B2[n-1];
    // for(ll i=1; i<n; i++)
    // {
    //     ll tt = B2[i];
    //     B2[i] = tem;
    //     tem = tt;
    // }
    // for(auto &e:B2) cout<<e<<" "; cout<<endl;
    // for(auto &e:A2) cout<<e<<" ";
    if (val(B2, A2, n)) {
        yes;
        return;
    }
    no;
}


int main() {
    ALLAHU_AKBAR

    ll t = 1;
    cin>>t;
    while(t--)
    {
        sir3();
    }
    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:54:44
Judged At
2025-06-13 16:54:44
Judged By
Score
0
Total Time
28ms
Peak Memory
776.0 KiB