#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a=0,b=0;
int ties=0;
vector<int> golovi;
for(int i=0;i<n;i++)
{
if(a==b) ties++;
int gol;
cin>>gol;
golovi.push_back(gol);
if(gol==1) a++;
else b++;
}
int ta=0,tb=0;
int i=1;
int mx=0;
while(i<n)
{
int t=1;
while(i<n && golovi[i]==golovi[i-1])
{
i++;
t++;
}
if(golovi[i-1]==1)
{
if(ta<tb && ta+t>tb) mx=max(mx,t);
ta+=t;
}
else
{
if(tb<ta && tb+t>ta) mx=max(mx,t);
tb+=t;
}
i++;
}
if(a==b) ties++;
cout<<a<<" "<<b<<endl;
cout<<ties<<endl;
cout<<mx<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |