/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 3ms 532.0 KiB
#3 Accepted 1ms 536.0 KiB
#4 Accepted 3ms 396.0 KiB
#5 Accepted 2ms 576.0 KiB
#6 Accepted 2ms 580.0 KiB
#7 Accepted 1ms 580.0 KiB
#8 Wrong Answer 1ms 532.0 KiB
#9 Wrong Answer 5ms 580.0 KiB

Code

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

#define ll long long
#define endl '\n'

const int nn = 2e5 + 17, mod = 1e9 + 7;
int n, A[nn];

bool pos(bool mxx) {
    int i = 1, j = n;
    deque<int>V;
    if (mxx) {
        V.push_back(A[1]);
        i++;
    }
    else {
        V.push_back(A[n]);
        j--;
    }
    
    while(i <= j) {
        int mx = V.back();
        int mn = V.front();
        if (A[i] >= A[j]) {
            if (A[j] >= mx) {
                V.push_back(A[j]);
                j--;
            }
            else if (A[i] >= mx) {
                V.push_back(A[i]);
                i++;
            }
            else {
                V.push_front(A[i]);
                i++;
            }
        }   
        else {
            if (A[i] >= mx) {
                V.push_back(A[i]);
                i++;
            }
            else if (A[j] >= mx) {
                V.push_back(A[j]);
                j--;
            }
            else {
                V.push_front(A[j]);
                j--;
            }
        }
        
    } 
    
    bool s = true;
    for (int i = 1; i < V.size(); i++) {
        if (V[i] < V[i - 1]) return false;
    }
    return true;
}

void Try() {
    cin >> n;
    //n = 5;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        //A[i] = 5;
    }
    
    if (pos(1) || pos(0)) cout << "YES\n";
    else cout << "NO\n";
    
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        Try();
    }

}

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 07:40:04
Judged At
2025-09-01 07:40:04
Judged By
Score
70
Total Time
5ms
Peak Memory
580.0 KiB