# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061144 | Kerim | Sequence (APIO23_sequence) | C++17 | 51 ms | 16460 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 <vector>
#include "bits/stdc++.h"
using namespace std;
int sequence(int N, std::vector<int> arr) {
int cnt = 0;
vector<int> one{0}, two{0};
vector<int> A(N+1), B(N+1);
for (int i = 0; i < N; i++){
int x = arr[i];
assert(1 <= x and x <= 3);
A[i+1] = A[i]-1;
B[i+1] = B[i]-1;
if (x == 1)
A[i+1] += 2, one.push_back(i+1);
else if (x == 3)
B[i+1] += 2, two.push_back(i+1);
else
cnt += 1;
}
int st = 1, en = N;
while (st < en){
int mid = (st+en+1) >> 1;
bool ok = 0;
for (int i = mid; i < one.size(); i++)
ok |= (A[one[i]] >= A[one[i-mid]]);
for (int i = mid; i < two.size(); i++)
ok |= (B[two[i]] >= B[two[i-mid]]);
if (ok)
st = mid;
else
en = mid-1;
}
return max(cnt, st);
}
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... |