/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 1ms 424.0 KiB
#4 Accepted 2ms 532.0 KiB
#5 Accepted 3ms 532.0 KiB
#6 Wrong Answer 5ms 536.0 KiB
#7 Wrong Answer 4ms 532.0 KiB

Code

#include <bits/stdc++.h>     //   All praise is due to Allah alone, and peace and blessings be
using namespace std;         //         upon him, after whom there is no other Prophet.

int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    int32_t Case = 1;    cin >> Case;
    for (int T = 1; T <= Case; T++) {

        int n; cin >> n;
        int ar[n]; for(int & i : ar) cin >> i;

        function<void()> Test_Case = [&]() {
            deque<int> br;
            int i = 0, j = n - 1;
            while(i <= j) {
                if(ar[i] <= ar[j]) {
                    if(br.empty()) {
                        br.emplace_back(ar[i++]);
                        continue;
                    }
                    else {
                        if(ar[i] <= br.front()) {
                            br.push_front(ar[i++]);
                            continue;
                        }
                        else if(ar[i] >= br.back()) {
                            br.push_back(ar[i++]);
                            continue;
                        }
                        else if(ar[j] >= br.back()) {
                            br.push_back(ar[j--]);
                            continue;
                        }
                        else if(ar[j] <= br.front()) {
                            br.push_front(ar[j--]); continue;
                        }
                        else {
                            cout << "NO\n";
                            return;
                        }
                    }
                }
                else {
                    if(br.empty()) {
                        br.emplace_back(ar[j--]);
                    }
                    else {
                        if(ar[j] <= br.front()) {
                            br.push_front(ar[j--]);
                            continue;
                        }
                        else if(ar[j] >= br.back()) {
                            br.push_back(ar[j--]);
                            continue;
                        }
                        else if(ar[i] >= br.back()) {
                            br.push_back(ar[i++]);
                            continue;
                        }
                        else if(ar[i] <= br.front()) {
                            br.push_front(ar[i++]); continue;
                        }
                        else {
                            cout << "NO\n";
                            return;
                        }
                    }
                }
            }
            // for(int i : br) cout << i << ' '; cout << '\n';
            if(is_sorted(br.begin(), br.end())) {
                cout << "YES\n";
            }
            else cout << "NO\n";
        };
        Test_Case();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 17:18:31
Judged At
2025-09-02 17:18:31
Judged By
Score
50
Total Time
5ms
Peak Memory
536.0 KiB