#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
preokret.cpp: In function 'int main()':
preokret.cpp:38:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
38 | if(pre[i] <= 0 && pre[j] <= 0 || pre[i] >= 0 && pre[j] >= 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 |
1 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 |
1 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 |