Submission #495995

#TimeUsernameProblemLanguageResultExecution timeMemory
495995AlperenTPreokret (COCI19_preokret)C++17
50 / 50
0 ms204 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...