/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 4ms 576.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 3ms 532.0 KiB
#5 Accepted 8ms 532.0 KiB
#6 Accepted 8ms 444.0 KiB
#7 Wrong Answer 4ms 492.0 KiB
#8 Wrong Answer 5ms 532.0 KiB

Code

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

typedef long long ll;
typedef double dl;

#define endl "\n"
#define vi vector<int>
#define mii map<int,int>
#define mci map<char,int>
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;

void solve(){
    int n; cin >> n;

    int ar[n+10], ar2[n+10];

    for(int i = 0; i < n; i++){
        cin >> ar[i];
        ar2[i] = ar[i];
        //mp[ar[i]]++;
    }

    sort(ar2, ar2+n);

    int i = 0, j = n-1, k = 0;

    bool b1 = true, b2 = true;

    for(int m = 0; m < n; m++){
        if(ar[i] == ar2[k]){
            i++;
            k++;
        }
        else if(ar[j] == ar2[k]){
            j--;
            k++;
        }
        //else if(ar[])
        else{
            b1 = false;
        }
    }

    if(b1 == true )  {
            yes
            return;
    }

    int ar3[n+10];
    int lk = n-1;

    k = 0;

    for(int l = 0; l < n; l++){
        ar3[l] = ar2[lk];
        lk--;
    }

    for(int m = 0; m < n; m++){
        if(ar[i] == ar3[k]){
            i++;
            k++;
        }
        else if(ar[j] == ar3[k]){
            j--;
            k++;
        }
        //else if(ar[])
        else{
                no

            return;
        }
    }

    yes





}

int main()
{
    optimize();

    int t;
    cin >> t;

    while(t--)  solve();

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Contest
LUCC Presents Kick & Code Intra LU Programming Contest
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-01 06:16:42
Judged At
2025-09-01 06:16:42
Judged By
Score
60
Total Time
8ms
Peak Memory
576.0 KiB