답안 #199062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199062 2020-01-29T02:30:28 Z virchau13 Preokret (COCI19_preokret) C++17
44 / 50
5 ms 376 KB
#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n], *c = new int[n+2]+2, *p = new int[n+2]+2;
    int t = 1;
    c[-1] = p[-1] = c[-2] = p[-2] = 0;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        c[i] = c[i-1] + (arr[i] == 1);
        p[i] = p[i-1] + (arr[i] == 2);
        if(c[i] == p[i]) t++;
    }
    int cx = -1, px = -1, m = 0;
    bool cr = 0, pr = 0;
    for(int i = 0; i < n; i++){
        if(c[i] != c[i-1]+1){
            if(cr) m = max(m, c[i]-c[cx]);
            cx = i;
            cr = c[i] < p[i];
        }
        if(p[i] != p[i-1]+1){
            if(pr) m = max(m, p[i]-p[px]);
            px = i;
            pr = p[i] < c[i];
        }
    }
    if(cr) m = max(m, c[n-1]-c[cx]);
    if(pr) m = max(m, p[n-1]-p[px]);
    cout << c[n-1] << ' ' << p[n-1] << '\n';
    cout << t << '\n';
    cout << m << '\n';
    // delete[] (c-2);
    // delete[] (p-2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Partially correct 5 ms 256 KB Output is partially correct
8 Correct 5 ms 256 KB Output is correct
9 Partially correct 5 ms 256 KB Output is partially correct
10 Correct 5 ms 256 KB Output is correct