# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
495996 | Nimbostratus | Preokret (COCI19_preokret) | C++17 | 1 ms | 216 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 "bits/stdc++.h"
#define endl '\n'
#define fi first
#define se second
constexpr int maxn = 2e5 + 5;
constexpr int inf = 2e9;
constexpr int mod = 1e9 + 7;
using namespace std;
using lint = long long;
using pii = pair<int, int>;
int n;
int a[maxn];
int g1, g2, d, turn;
int pre[maxn];
bool w1;
signed main() {
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
d = 1;
for(int i = 1; i <= n; i++) {
g1 += a[i] == 1;
g2 += a[i] == 2;
pre[i] = pre[i - 1];
pre[i] += a[i] == 1 ? 1 : -1;
d += g1 == g2;
}
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++) {
if(pre[i] < 0 && pre[j] < 0 || pre[i] > 0 && pre[j] > 0)
continue;
int cur = j - i;
int x = pre[i] > pre[j] ? -1 : 1;
for(int k = i; k < j; k++)
if(pre[k + 1] - pre[k] != x)
cur = 0;
turn = max(turn, cur);
}
cout << g1 << " " << g2 << endl;
cout << d << endl;
cout << turn << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |