# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199059 | virchau13 | Preokret (COCI19_preokret) | C++17 | 5 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 0, px = 0, 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);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |