Submission #764574

#TimeUsernameProblemLanguageResultExecution timeMemory
7645741075508020060209tcPreokret (COCI19_preokret)C++14
50 / 50
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second int n; int ar[500005]; int A[500005]; int B[500005]; signed main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>ar[i]; } int rv=0; int te=1; for(int i=1;i<=n;i++){ A[i]=A[i-1]; B[i]=B[i-1]; if(ar[i]==1){ A[i]++; }else{ B[i]++; } if(A[i]==B[i]){te++;} } for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(ar[i]==1){ if(A[j]-A[i-1]!=j-i+1){continue;} if(A[i]<B[i]&&A[j]>B[j]){ rv=max(rv,j-i+1ll); } }else{ if(B[j]-B[i-1]!=j-i+1){continue;} if(B[i]<A[i]&&B[j]>A[j]){ rv=max(rv,j-i+1ll); } } } } cout<<A[n]<<" "<<B[n]<<endl; cout<<te<<endl; cout<<rv<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...