#include <stdio.h>
#define N 250
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N];
int n, i, j, a, b, t, l;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
a = 0, b = 0, t = 1, l = 0;
for (i = 0; i < n; i = j) {
int c;
j = i, c = a - b;
while (j < n && aa[j] == aa[i]) {
if (aa[j] == 1)
a++;
else
b++;
if (a == b)
t++;
j++;
}
if (c > 0 && a - b < 0 || c < 0 && a - b > 0)
l = max(l, j - i);
}
printf("%d %d\n", a, b);
printf("%d\n", t);
printf("%d\n", l);
return 0;
}
Compilation message
preokret.c: In function 'main':
preokret.c:28:13: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
28 | if (c > 0 && a - b < 0 || c < 0 && a - b > 0)
| ~~~~~~^~~~~~~~~~~~
preokret.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
preokret.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
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 |
276 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
276 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
272 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |