#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3+1,mod=1e9+7;
main(){
int n;
cin>>n;
int sum1=0,sum2=0;
int i=0;
int x;
int Final_ans=0;
int ans=0;
int ok1=0,ok2=0;
int anss=0;
while(i<n){
cin>>x;
if(ok1==1&&x==1)
ans++,ok2=0,sum1++;
else if(ok2==1&&x==2)
ans++,ok1=0,sum2++;
else if(x==1&&sum1>=sum2)
sum1++,ok2=0;
else if(x==2&&sum2>=sum1)
sum2++,ok1=0;
else if(ok1==0&&x==1&&sum1<sum2){
ok1=1;
ans=1;
sum1++;
ok2=0;
}
else if(ok2==0&&x==2&&sum2<sum1){
ans=1;
ok2=1;
sum2++;
ok1=0;
}
i++;
if(sum1==sum2)
anss++;
if(ok1==1&&sum1>sum2)
Final_ans=max(Final_ans,ans);
if(ok2==1&&sum2>sum1)
Final_ans=max(Final_ans,ans);
}
cout<<sum1<<" "<<sum2<<endl;
cout<<anss+1<<endl;
cout<<Final_ans<<endl;
return 0;
}
Compilation message
preokret.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |