Submission #866416

#TimeUsernameProblemLanguageResultExecution timeMemory
866416vjudge1Preokret (COCI19_preokret)C++17
50 / 50
1 ms348 KiB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;






void solve(){
    int n; cin >> n;
    int cit=0, opp=0, tie=1, citS=0, oppS=0, val=0, ans=0;
    for(int i=1; i<=n; i++){
        int a; cin >> a;
        if(a==1) cit++;
        else opp++;
        if(cit==opp) tie++;

        if(a==1){
            if(citS==0){
                if(val && opp>cit) ans = max(ans, oppS);
                if(cit<=opp) val=1;
                else val=0;
            }
            citS++;
            oppS=0;
        }
        else{
            if(oppS==0){
                if(val && cit>opp) ans = max(ans, citS);
                if(opp<=cit) val=1;
                else val=0;
            }
            oppS++;
            citS=0;
            if(val) ans = max(ans, oppS);
        }
    }
    if(val==1){
        if(cit>opp) ans = max(ans, citS);
        else ans = max(ans, oppS);
    }

    cout << cit spc opp << endl;
    cout << tie << endl;
    cout << ans << endl;
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif

    int t=1;
    //cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...