/ 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 532.0 KiB
#5 Accepted 2ms 576.0 KiB
#6 Accepted 3ms 532.0 KiB
#7 Accepted 3ms 532.0 KiB
#8 Wrong Answer 5ms 492.0 KiB
#9 Wrong Answer 22ms 580.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dt = array<int, 2>;

bool ok(deque<int> in, deque<int> out) {
  while (out.size()) {
    if (out.front() == out.back()) {
      if (out.front() >= in.back()) {
        in.push_back(out.front());
        out.pop_front();
      } else if (out.front() <= in.front()) {
        in.push_front(out.front());
        out.pop_front();
      } else {
        return false;
      }
    } else if (out.front() < out.back()) {
      if (out.front() >= in.back()) {
        in.push_back(out.front());
        out.pop_front();
        continue;
      }
      if (out.back() <= in.front()) {
        in.push_front(out.back());
        out.pop_back();
        continue;
      }
      if (out.front() <= in.front()) {
        in.push_front(out.front());
        out.pop_front();
        continue;
      }
      if (out.back() >= in.back()) {
        in.push_back(out.back());
        out.pop_back();
        continue;
      }
      return false;
    } else {
      if (out.back() >= in.back()) {
        in.push_back(out.back());
        out.pop_back();
        continue;
      }
      if (out.front() <= in.front()) {
        in.push_front(out.front());
        out.pop_front();
        continue;
      }
      if (out.back() <= in.front()) {
        in.push_front(out.back());
        out.pop_back();
        continue;
      }
      if (out.front() >= in.back()) {
        in.push_back(out.front());
        out.pop_front();
        continue;
      }
      return false;
    }
  }
  // for (auto e : in) cout << e << " ";
  //   cout << "\n";
  return true;
}

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

  deque<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }

  auto a = v;

  deque<int> final;
  final.push_back(v.front());
  v.pop_front();

  if (ok(final, v)) {
    cout << "YES\n";
    return;
  } 

  v = a;
  final.clear();
  final.push_back(v.back());
  v.pop_back();
  if (ok(final, v)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;  
  cin >> T;
  for (int i = 1; i <= T; i++) {
    test();
  }
  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:07:01
Judged At
2025-09-02 17:07:01
Judged By
Score
70
Total Time
22ms
Peak Memory
580.0 KiB