# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
837083 | aZvezda | Sequence (APIO23_sequence) | C++17 | 2054 ms | 52492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sequence.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e6 + 10;
vector<int> where[MAX_N];
int small[MAX_N], big[MAX_N];
int arr[MAX_N];
int sequence(int n, std::vector<int> A) {
for(int i = 0; i < n; i ++) {
arr[i + 1] = A[i];
}
for(int i = 1; i <= n; i ++) {
where[arr[i]].push_back(i);
}
int ans = 0;
for(int val = 0; val <= n; val ++) {
if(where[val].empty()) { continue; }
for(int i = 1; i <= n; i ++) {
small[i] = (arr[i] < val) + small[i - 1];
big[i] = (arr[i] > val) + big[i - 1];
}
for(int i = 0; i < where[val].size(); i ++) {
int l = where[val][i];
for(int j = i + 1; j < where[val].size(); j ++) {
int r = where[val][j];
if(2 * (small[r] - small[l - 1]) <= (r - l + 1) && 2 * (big[r] - big[l - 1]) <= (r - l + 1)) {
ans = max(ans, j - i + 1);
}
}
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |