#include <bits/stdc++.h>
using namespace std;
const int N = 250 + 5;
int n, arr[N], ties, turnover, cnt[N];
pair<int, int> score[N];
int winner(pair<int, int> p){
if(p.first > p.second) return 1;
else if(p.second > p.first) return 2;
else return -1;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++) cin >> arr[i];
for(int i = 1; i <= n; i++) score[i] = {score[i - 1].first + (arr[i] == 1), score[i - 1].second + (arr[i] == 2)};
for(int i = 1; i <= n; i++){
if(arr[i] == arr[i - 1]) cnt[i] = cnt[i - 1] + 1, cnt[i - 1] = 0;
else cnt[i] = 1;
}
for(int i = 0; i <= n; i++) if(score[i].first == score[i].second) ties++;
for(int i = 1; i <= n; i++){
if(arr[i] == 1){
if(winner(score[i - cnt[i]]) == 2 && winner(score[i]) == 1) turnover = max(turnover, cnt[i]);
}
else if(arr[i] == 2){
if(winner(score[i - cnt[i]]) == 1 && winner(score[i]) == 2) turnover = max(turnover, cnt[i]);
}
}
cout << count(arr + 1, arr + n + 1, 1) << " " << count(arr + 1, arr + n + 1, 2) << "\n";
cout << ties << "\n";
cout << turnover;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |