#include <bits/stdc++.h>
using namespace std;
int n;
int s1[300];
int s2[300];
//ideja je samo simulacija
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
cin >> n;
s1[0] = 0;
s2[0] = 0;
int cnt = 1;
int c1 = 0;
int c2 = 0;
int ma = -1;
for(int i=1;i<=n;i++)
{
int x;
cin >> x;
if(x==1)
{
s1[i] = s1[i-1]+1;
s2[i] = s2[i-1];
if(c1==0)
{
if(c2!=0)
{
//cout << "uso 1" << "\n";
int pre = i-1-c2;
int kraj = i-1;
if(s1[pre] > s2[pre] && s2[kraj] > s1[kraj]) ma = max(ma,c2);
}
c2=0;
}
c1++;
}
else
{
s1[i] = s1[i-1];
s2[i] = s2[i-1] +1;
if(c2==0)
{
if(c1!=0)
{
//cout << "uso 2" << "\n";
int pre = i-1-c1;
int kraj = i-1;
if(s1[pre] < s2[pre] && s2[kraj] < s1[kraj]) ma = max(ma,c1);
}
c1=0;
}
c2++;
}
if(s1[i] == s2[i]) cnt++;
}
if(c1!=0)
{
//cout << "uso 1 kr" << "\n";
int pre = n-c1;
int kraj = n;
if(s1[pre] < s2[pre] && s2[kraj] < s1[kraj]) ma = max(ma,c1);
}
if(c2!=0)
{
//cout << "uso 2 kr" << "\n";
int pre = n-c2;
int kraj = n;
//cout << s1[pre] << " " << s2[pre] << " " << s1[kraj] << " " << s2[kraj] << "\n";
if(s1[pre] > s2[pre] && s2[kraj] > s1[kraj]) ma = max(ma,c2);
}
cout << s1[n] << " " << s2[n] << "\n" << cnt << "\n" << ma;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
508 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |