Submission #495998

# Submission time Handle Problem Language Result Execution time Memory
495998 2021-12-20T10:35:41 Z ktkerem Preokret (COCI19_preokret) C++17
50 / 50
1 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define debu cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e13 + 7; 
const ll ous=1e5 + 5;
const ll dx[4] = {0 , -1 , 1 , 0} , dy[4] = {1,0,0,-1};
void solve(){
    ll n;cin >> n;
    ll ar[n];ll ft=0 , st=0 , tc = 1;
    fora(i,n){
        cin >> ar[i];
        if(ar[i] == 1){
            ft++;
        }
        else{
            st++;
        }
        if(ft == st){
            tc++;
        }
    }
    cout << ft << " " << st << "\n";
    cout << tc << "\n";
    ft = st =0;
    ll tp[2][n+1];
    memset(tp , 0 , sizeof(tp));
    if(ar[0] == 1){
        ft++;
    }
    else{
        st++;
    }
    ll mx = 0;
    for(ll i = 1;n>i;i++){
        if(ar[i] != ar[i-1]){
            if(tp[0][i-1] > tp[1][i-1]){
                if(ft > st){
                    mx = max(mx , tp[0][i-1]);
                }
            }
            else if(tp[0][i-1] < tp[1][i-1]){
                if(ft < st){
                    mx = max(mx , tp[1][i-1]);
                }   
            }
        }
        if(ar[i] == 1){
            if(ar[i-1] == ar[i] && tp[ar[i]-1][i-1] != 0){
                tp[ar[i]-1][i] = tp[ar[i]-1][i-1]+1;
            }
            else if(st > ft){
                tp[ar[i]-1][i] = 1;
            }
            else{
                tp[ar[i]-1][i]=0;
            }
            ft++;
        }
        else{
            if(ar[i-1] == ar[i] && tp[ar[i]-1][i-1] != 0){
                tp[ar[i]-1][i] = tp[ar[i]-1][i-1]+1;
            }
            else if(st < ft){
                tp[ar[i]-1][i] = 1;
            }
            else{
                tp[ar[i]-1][i]=0;
            }
            st++;
        }
    }
    if(tp[0][n-1] > tp[1][n-1]){
        if(ft > st){
            mx = max(mx , tp[0][n-1]);
        }
    }
    else if(tp[0][n-1] < tp[1][n-1]){
        if(ft < st){
            mx = max(mx , tp[1][n-1]);
        }   
    }
    cout << mx << "\n";
    return;/**/
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct