/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 20ms 3.375 MiB
#2 Accepted 23ms 4.988 MiB
#3 Accepted 17ms 3.535 MiB
#4 Accepted 23ms 3.77 MiB
#5 Accepted 20ms 4.27 MiB
#6 Accepted 20ms 3.93 MiB
#7 Wrong Answer 16ms 3.441 MiB

Code

import sys
from collections import deque

def solve():
    """
    Solves a single test case for the beautiful array problem.
    """
    try:
        n = int(sys.stdin.readline())
        a = list(map(int, sys.stdin.readline().split()))
    except (IOError, ValueError):
        return

    # A deque for efficient removal from both ends
    a_deque = deque(a)
    
    # A sorted version for reference
    a_sorted = sorted(a)

    # Pointers for the sorted reference array
    left_s = 0
    right_s = n - 1

    possible = True
    while a_deque:
        # These are the smallest and largest elements we need to find
        target_min = a_sorted[left_s]
        target_max = a_sorted[right_s]

        # Check the left end of the current array A
        if a_deque[0] == target_min:
            a_deque.popleft()
            left_s += 1
        elif a_deque[0] == target_max:
            a_deque.popleft()
            right_s -= 1
        # Check the right end of the current array A
        elif a_deque[-1] == target_min:
            a_deque.pop()
            left_s += 1
        elif a_deque[-1] == target_max:
            a_deque.pop()
            right_s -= 1
        # If no match is found, it's impossible
        else:
            possible = False
            break

    if possible:
        print("YES")
    else:
        print("NO")

def main():
    """
    Main function to handle multiple test cases.
    """
    try:
        num_test_cases = int(sys.stdin.readline())
        for _ in range(num_test_cases):
            solve()
    except (IOError, ValueError):
        pass

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Contest
Testing - Intra LU Programming contest 25
Language
Python 3 (Python 3.12.3)
Submit At
2025-08-30 20:15:31
Judged At
2025-08-30 20:15:31
Judged By
Score
50
Total Time
23ms
Peak Memory
4.988 MiB