답안 #764574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764574 2023-06-23T15:50:41 Z 1075508020060209tc Preokret (COCI19_preokret) C++14
50 / 50
1 ms 340 KB
#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;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 308 KB Output is correct