Submission #974376

#TimeUsernameProblemLanguageResultExecution timeMemory
974376isirazeevSequence (APIO23_sequence)C++17
11 / 100
2073 ms31568 KiB
#include <bits/stdc++.h>

using namespace std;

int sequence(int n, vector<int> a) {
    vector<int> pos[n + 1];
    for (int i = 0; i < n; i++) pos[a[i]].emplace_back(i);
    int res = 0;
    for (int val = 1; val <= n; val++) {
        for (int L = 0; L < n; L++) {
            int c1 = 0, c2 = 0;
            for (int R = L; R < n; R++) {
                c1 += (a[R] < val), c2 += (a[R] > val);
                if(abs(c1 - c2) <= (R - L + 1) - (c1 + c2) && (R - L + 1) > c1 + c2){
                    res = max(res, R - L + 1 - c1 - c2);
                }
            }
        }
    }
    return res;
}

//int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr), cout.tie(nullptr);
//    int N;
//    cin >> N;
//    vector<int> A(N);
//    for (int i = 0; i < N; i++) cin >> A[i];
//    cout << sequence(N, A);
//    return 0;
//}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...