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 <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
int32_t sequence(int32_t N, std::vector<int32_t> A) {
int32_t ans = 0;
auto calc = [&](int len,int curr){
vector<int32_t> cnt(4);
if(len>N)return false;
for(int i=0;i<len-1;i++)cnt[A[i]]++;
bool works = false;
for(int i=len-1;i<N;i++){
cnt[A[i]]++;
if(i-len>=0)cnt[A[i-len]]--;
int lower,upper;
if(curr==1){
lower = 0;
upper = cnt[1]-1;
} else if(curr==2){
lower = cnt[1];
upper = cnt[2]+cnt[1]-1;
} else {
lower = cnt[2]+cnt[1];
upper = len-1;
}
if(len/2<=upper and lower<=len/2){
ans = max(ans,cnt[curr]);
works = true;
}
if(len%2==0 and (len/2)-1 <= upper and (len/2)-1 >= lower){
ans = max(ans,cnt[curr]);
works = true;
}
}
return works;
};
for(int i=1;i<=3;i++){
int curr = 0;
for(int jump=262144;jump;jump/=2)if(calc(curr+jump,i))curr+=jump;
}
return ans;
}
# | 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... |