# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
970504 | anton | Sequence (APIO23_sequence) | C++17 | 82 ms | 10840 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;
#define ll long long
#define pii pair<int, int>
struct MStack{
vector<pii> st;
void push_back(pii val){
if(st.size()==0 || val.first<st.back().first){
st.push_back(val);
}
}
int first_under(int h){
int cur= 0;
if(st[0].first<=h){
return -1;
}
for(int step = (1<<20); step>=1; step/=2){
if(cur+step<st.size()){
if(st[cur+step].first>h){
cur+=step;
}
}
}
if(cur == st.size()-1){
return 1e9;
}
else{
return st[cur+1].second;
}
}
};
int sequence(int N, std::vector<int> A) {
vector<int> a;
vector<int> oc(3, 0);
for(int i = 0; i<N; i++){
oc[A[i]-1] ++;
a.push_back(A[i]-1);
}
for(int i = 0; i<3; i++){
if(2*oc[i]>= N){
return oc[i];
}
}
int res= max(oc[1], 1);
for(int color =0; color<3; color+=2){
int K =0;
int S =0;
MStack vals;
vals.push_back({0, -1});
for(int i = 0; i<N; i++){
K++;
if(a[i] == color){
S++;
}
//cout<<"id "<<vals.first_under(2*S-K)<<" "<<i<<endl;
res = max(res, (i-vals.first_under(2*S-K)+1)/2);
//cout<<"val "<<i<<" "<<2*S-K<<endl;
vals.push_back({2*S-K, i});
}
}
return res;
}
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... |