# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
823744 | hmm789 | Sequence (APIO23_sequence) | C++17 | 48 ms | 15980 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;
int sequence(int N, std::vector<int> A) {
#define int long long
int ans = 0, tup = 1, tdown = 0;
vector<pair<int, int>> up, down;
bool f = true; // true -> up, false -> down
up.push_back({A[0], 1});
for(int i = 1; i < N; i++) {
if(A[i] < A[i-1]) f = false;
if(f) {
if(A[i] == up.back().first) {
up.back().second++;
} else {
up.push_back({A[i], 1});
}
tup++;
} else {
if(!down.empty() && A[i] == down.back().first) {
down.back().second++;
} else {
down.push_back({A[i], 1});
}
tdown++;
}
}
int i1 = 0, i2 = down.size()-1;
while(i1 < up.size() && i2 >= 0) {
if(up[i1].first < down[i2].first) {
ans = max(ans, up[i1].second);
tup -= up[i1].second;
i1++;
} else if(up[i1].first > down[i2].first) {
ans = max(ans, down[i2].second);
tdown -= down[i2].second;
i2--;
} else {
if(tup+tdown-up[i1].second-down[i2].second <= N/2) ans = max(ans, up[i1].second+down[i2].second);
tup -= up[i1].second;
tdown -= down[i2].second;
i1++;
i2--;
}
}
while(i1 < up.size()) {
ans = max(ans, up[i1].second);
i1++;
}
while(i2 >= 0) {
ans = max(ans, down[i2].second);
i2--;
}
return ans;
#undef int
}
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... |