/ SeriousOJ /

Record Detail

Wrong Answer


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

Code

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

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& ai : a) {
    cin >> ai;
  }
  int l = 0, r = n - 1;
  deque<int> b;
  a[l] <= a[r] ? b.push_back(a[l++]) : b.push_back(a[r--]);
  while (l <= r) {
    if (a[l] <= a[r]) {
      b.back() <= a[l] ? b.push_back(a[l++]) : b.push_front(a[l++]);
    } else {
      b.back() <= a[r] ? b.push_back(a[r--]) : b.push_front(a[r--]);
    }
  }
  cout << (is_sorted(b.begin(), b.end()) ? "YES" : "NO") << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  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 16:16:17
Judged At
2025-09-02 16:16:17
Judged By
Score
50
Total Time
5ms
Peak Memory
584.0 KiB