/ 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 3ms 532.0 KiB
#6 Accepted 3ms 604.0 KiB
#7 Wrong Answer 2ms 532.0 KiB
#8 Wrong Answer 3ms 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;
        vector<int> br(ar, ar + n);
        sort(br.begin(), br.end());

        function<void()> Test_Case = [&]() {
            int i = 0, j = n - 1;
            auto it = lower_bound(br.begin(), br.end(), ar[i]);
            int ind = it - br.begin();
            i++;
            int l = ind - 1, r = ind + 1;
            while(i <= j) {
                if(l >= 0 and ar[i] == br[l]) {
                    i++, l--;
                }
                else if(r < n and ar[i] == br[r]) {
                    i++, r++;
                }
                else if(l >= 0 and ar[j] == br[l]) {
                    j--, l--;
                }
                else if(r < n and ar[j] == br[r]) {
                    j--, r++;
                }
                else {
                    break;
                }
            }
            i = 0, j = n - 1;
            it = lower_bound(br.begin(), br.end(), ar[j]);
            j--;
            ind = it - br.begin();
            l = ind - 1, r = ind + 1;
            while(i <= j) {
                if(l >= 0 and ar[i] == br[l]) {
                    i++, l--;
                }
                else if(r < n and ar[i] == br[r]) {
                    i++, r++;
                }
                else if(l >= 0 and ar[j] == br[l]) {
                    j--, l--;
                }
                else if(r < n and ar[j] == br[r]) {
                    j--, r++;
                }
                else {
                    cout << "NO\n"; return;
                }
            }
            cout << "YES\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:42:53
Judged At
2025-09-02 17:42:53
Judged By
Score
60
Total Time
3ms
Peak Memory
604.0 KiB