/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 4ms 580.0 KiB
#3 Accepted 1ms 348.0 KiB
#4 Accepted 3ms 532.0 KiB
#5 Accepted 3ms 532.0 KiB
#6 Accepted 9ms 600.0 KiB
#7 Wrong Answer 4ms 532.0 KiB
#8 Wrong Answer 5ms 540.0 KiB

Code

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

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

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

  auto a = v;
  auto c = a;
  sort(c.begin(), c.end());
  
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (c[i] == v.back()) {
    	v.pop_back();
    } else if (c[i] == v.front()) {
    	v.pop_front();
    } else {
    	ok = false;
    	break;
    }
  }

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

  v = a;
  ok = true;
  sort(c.begin(), c.end(), greater<>());
  for (int i = 0; i < n; i++) {
    if (c[i] == v.back()) {
    	v.pop_back();
    } else if (c[i] == v.front()) {
    	v.pop_front();
    } else {
    	ok = false;
    	break;
    }
  }

  if (ok) {
  	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 16:11:38
Judged At
2025-09-02 16:11:38
Judged By
Score
60
Total Time
9ms
Peak Memory
600.0 KiB