/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 524.0 KiB
#2 Accepted 7ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 9ms 584.0 KiB
#5 Wrong Answer 4ms 532.0 KiB

Code

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

int main() {
    int t;  
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<int> A(n);
        for (int i = 0; i < n; ++i) {
            cin >> A[i];
        }

       
        vector<int> sortedA = A;
        sort(sortedA.begin(), sortedA.end());

        int left = 0;
        int right = n - 1;
        bool possible = true;

        
        for (int i = 0; i < n; ++i) {
            if (left <= right && sortedA[i] == A[left]) {
                left++;
            } else if (left <= right && sortedA[i] == A[right]) {
                right--;
            } else {
                possible = false;
                break;
            }
        }

        if (possible) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++11 (G++ 13.2.0)
Submit At
2025-09-02 16:34:19
Judged At
2025-09-02 16:34:19
Judged By
Score
30
Total Time
9ms
Peak Memory
584.0 KiB