Submission #300023

# Submission time Handle Problem Language Result Execution time Memory
300023 2020-09-16T07:00:07 Z ryuku1110 Preokret (COCI19_preokret) C++14
50 / 50
1 ms 384 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int n, city = 0, oppo = 0, d[252], TIE = 1, z[251];

int main() {
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; ++ i) {
        cin >> z[i];
        if (z[i] == 1) ++ city;
        else ++ oppo;
        if (city == oppo) ++ TIE;
        d[i] = city - oppo;
    }
    bool started = false;
    int st, en, ans = 0;

    z[n+1] = 2;
    for (int i = 1; i <= n; ++ i) {
        // cout << z[i] << " ";
        if (z[i] == 1 && started == false) {
            started = true;
            st = i;
        } 
        if (z[i + 1] == 2 && started == true) {
            started = false;
            en = i;
            if (d[st - 1] < 0 && d[en] > 0) {
                ans = max(ans, en - st + 1);
            }
        }
    }
    
    z[n+1] = 1;
    started = false;
    for (int i = 1; i <= n; ++ i) {
        if (z[i] == 2 && started == false) {
            started = true;
            st = i;
        } 
        if (z[i + 1] == 1 && started == true) {
            started = false;
            en = i;
            // cout << st << " " << en << endl;
            if (d[st - 1] > 0 && d[en] < 0) {
                ans = max(ans, en - st + 1);
            }
        }
    }

    cout << city << " " << oppo << endl;
    cout << TIE << endl;
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct