# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880194 | irmuun | Sequence (APIO23_sequence) | C++17 | 47 ms | 19652 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<bits/stdc++.h>
#include "sequence.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int sequence(int N,vector<int>A){
int mx=0;
for(auto x:A){
mx=max(mx,x);
}
if(mx<=3){
vector<int>cnt(4,0),c1(N+1,0),c3(N+1,0);
for(int i=0;i<N;i++){
cnt[A[i]]++;
c1[i+1]=c1[i]+(A[i]==1);
c3[i+1]=c3[i]+(A[i]==3);
}
if(cnt[1]>=cnt[2]+cnt[3]){
return cnt[1];
}
if(cnt[3]>=cnt[2]+cnt[1]){
return cnt[3];
}
int cur1=0,cur3=0,mn1,mn2,ans=cnt[2];
vector<pair<int,int>>s1,s3;
for(int i=0;i<N;i++){
cur1+=(A[i]==1?1:-1);
cur3+=(A[i]==3?1:-1);
s1.pb({cur1,i});
s3.pb({cur3,i});
}
sort(all(s1));
sort(all(s3));
set<int>st;
for(auto [c,i]:s1){
st.insert(i);
int x=*st.begin();
ans=max(ans,c1[i+1]-c1[x]);
}
st.clear();
for(auto [c,i]:s3){
st.insert(i);
int x=*st.begin();
ans=max(ans,c3[i+1]-c3[x]);
}
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... |