#include <bits/stdc++.h>
using namespace std;
int n, a[5000110];
int main () {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
bool y = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1 and a[i] < a[i - 1]) y = 0;
}
if (y) cout << "0\n";
int cntf[2] = {0}, cntb[2] = {0}, ans = INT_MAX;
for (int i = 1; i <= n; i++) {
if (a[i] == -1) cntb[0]++;
else cntb[1]++;
}
for (int i = 1; i <= n + 1; i++) {
if (cntb[0] % 2 == 0 and cntf[1] % 2 == 0) ans = min(ans, (cntb[0] + cntf[1]) >> 1 );
if (a[i] == -1) cntb[0]--, cntf[0]++;
else cntf[1]++, cntb[1]--;
}
if (ans == INT_MAX) ans = -1;
cout << ans << '\n';
return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |