Submission #1340116

#TimeUsernameProblemLanguageResultExecution timeMemory
1340116orgiloogiiPreokret (COCI19_preokret)C++20
50 / 50
1 ms344 KiB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
    int home = 0, away = 0;
    int ties = 1;
    int turnovers = 0;
    vector <int> goals;
    for (int i = 0;i < n;i++) {
        int g;
        cin >> g;
        goals.push_back(g);
        if (g == 1) {
            home++;
        }
        else {
            away++;
        }
        if (home == away) ties++;
    }   
    cout << home << ' ' << away << endl;
    cout << ties << endl;
    vector <pair <int, int>> streaks;
    int ls = 0;
    for (int i = 1;i < n;i++) {
        if (goals[i] != goals[i - 1]) {
            if (streaks.size() == 0) {
                streaks.push_back({goals[i - 1], i});
                ls = i - 1;
            }
            else {
                streaks.push_back({goals[i - 1], i - ls - 1});
                ls = i - 1;
            }
        }
    }
    streaks.push_back({goals[n - 1], n - ls - 1});
    int a = 0, b = 0;
    int ans = 0;
    for (auto [x, y] : streaks) {
        if (a == b) {
            if (x == 1) a += y;
            else b += y;
            continue;
        }
        if (a > b) {
            if (x == 1) {
                a += y;
                continue;
            }
            if (b + y > a) {
                ans = max(ans, y);
            }
            b += y;
        }
        else {
            if (x == 2) {
                b += y;
                continue;
            }
            if (a + y > b) {
                ans = max(ans, y);
            }
            a += y;
        }
        // cout << x << ' ' << y << endl;
    }
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...