# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
493279 |
2021-12-10T16:27:01 Z |
rainboy |
Cigle (COI21_cigle) |
C |
|
1000 ms |
46540 KB |
#include <stdio.h>
#include <string.h>
#define N 5000
#define N_ (1 << 13)
int max(int a, int b) { return a > b ? a : b; }
int ss[N_ * 2], pp[N_ * 2], n_;
void pul(int i) {
int l = i << 1, r = l | 1;
ss[i] = ss[l] + ss[r];
pp[i] = max(pp[l], ss[l] + pp[r]);
}
void update(int i, int x) {
i += n_;
pp[i] = ss[i] += x;
while (i > 1)
pul(i >>= 1);
}
int main() {
static int aa[N + 1], dp[N + 1][N + 1];
int n, i, j, k, ans;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &aa[i]);
aa[i] += aa[i - 1];
}
for (i = 1; i <= n; i++)
dp[0][i] = 0;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (j = 1; j <= n; j++) {
memset(ss, 0, n_ * 2 * sizeof *ss);
for (i = 0; i < j; i++) {
update(i, dp[i][j]);
if (i + 1 < n)
update(i + 1, -dp[i][j]);
}
for (k = j + 1, i = j - 1; k <= n; k++) {
dp[j][k] = pp[1];
while (i >= 0 && aa[i] + aa[k] > aa[j] * 2)
i--;
if (i >= 0 && aa[i] + aa[k] == aa[j] * 2)
update(0, 1), update(i, -1);
}
}
ans = 0;
for (i = 0; i < n; i++)
ans = max(ans, dp[i][n]);
printf("%d\n", ans);
return 0;
}
Compilation message
cigle.c: In function 'main':
cigle.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
cigle.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
540 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
540 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
540 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2756 KB |
Output is correct |
2 |
Correct |
23 ms |
2684 KB |
Output is correct |
3 |
Correct |
20 ms |
2712 KB |
Output is correct |
4 |
Correct |
21 ms |
2708 KB |
Output is correct |
5 |
Correct |
21 ms |
2820 KB |
Output is correct |
6 |
Correct |
24 ms |
2788 KB |
Output is correct |
7 |
Correct |
22 ms |
2720 KB |
Output is correct |
8 |
Correct |
21 ms |
2696 KB |
Output is correct |
9 |
Correct |
24 ms |
2764 KB |
Output is correct |
10 |
Correct |
21 ms |
2772 KB |
Output is correct |
11 |
Correct |
19 ms |
2704 KB |
Output is correct |
12 |
Correct |
22 ms |
2692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
540 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
540 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
540 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
20 ms |
2756 KB |
Output is correct |
22 |
Correct |
23 ms |
2684 KB |
Output is correct |
23 |
Correct |
20 ms |
2712 KB |
Output is correct |
24 |
Correct |
21 ms |
2708 KB |
Output is correct |
25 |
Correct |
21 ms |
2820 KB |
Output is correct |
26 |
Correct |
24 ms |
2788 KB |
Output is correct |
27 |
Correct |
22 ms |
2720 KB |
Output is correct |
28 |
Correct |
21 ms |
2696 KB |
Output is correct |
29 |
Correct |
24 ms |
2764 KB |
Output is correct |
30 |
Correct |
21 ms |
2772 KB |
Output is correct |
31 |
Correct |
19 ms |
2704 KB |
Output is correct |
32 |
Correct |
22 ms |
2692 KB |
Output is correct |
33 |
Correct |
20 ms |
2764 KB |
Output is correct |
34 |
Correct |
23 ms |
2756 KB |
Output is correct |
35 |
Correct |
22 ms |
2792 KB |
Output is correct |
36 |
Correct |
21 ms |
2744 KB |
Output is correct |
37 |
Correct |
22 ms |
2728 KB |
Output is correct |
38 |
Correct |
23 ms |
2792 KB |
Output is correct |
39 |
Correct |
19 ms |
2700 KB |
Output is correct |
40 |
Correct |
18 ms |
2740 KB |
Output is correct |
41 |
Correct |
20 ms |
2812 KB |
Output is correct |
42 |
Correct |
18 ms |
2764 KB |
Output is correct |
43 |
Correct |
18 ms |
2720 KB |
Output is correct |
44 |
Correct |
18 ms |
2732 KB |
Output is correct |
45 |
Correct |
17 ms |
2712 KB |
Output is correct |
46 |
Correct |
17 ms |
2736 KB |
Output is correct |
47 |
Correct |
16 ms |
2740 KB |
Output is correct |
48 |
Correct |
16 ms |
2728 KB |
Output is correct |
49 |
Correct |
17 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
540 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
540 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
540 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
20 ms |
2756 KB |
Output is correct |
22 |
Correct |
23 ms |
2684 KB |
Output is correct |
23 |
Correct |
20 ms |
2712 KB |
Output is correct |
24 |
Correct |
21 ms |
2708 KB |
Output is correct |
25 |
Correct |
21 ms |
2820 KB |
Output is correct |
26 |
Correct |
24 ms |
2788 KB |
Output is correct |
27 |
Correct |
22 ms |
2720 KB |
Output is correct |
28 |
Correct |
21 ms |
2696 KB |
Output is correct |
29 |
Correct |
24 ms |
2764 KB |
Output is correct |
30 |
Correct |
21 ms |
2772 KB |
Output is correct |
31 |
Correct |
19 ms |
2704 KB |
Output is correct |
32 |
Correct |
22 ms |
2692 KB |
Output is correct |
33 |
Correct |
20 ms |
2764 KB |
Output is correct |
34 |
Correct |
23 ms |
2756 KB |
Output is correct |
35 |
Correct |
22 ms |
2792 KB |
Output is correct |
36 |
Correct |
21 ms |
2744 KB |
Output is correct |
37 |
Correct |
22 ms |
2728 KB |
Output is correct |
38 |
Correct |
23 ms |
2792 KB |
Output is correct |
39 |
Correct |
19 ms |
2700 KB |
Output is correct |
40 |
Correct |
18 ms |
2740 KB |
Output is correct |
41 |
Correct |
20 ms |
2812 KB |
Output is correct |
42 |
Correct |
18 ms |
2764 KB |
Output is correct |
43 |
Correct |
18 ms |
2720 KB |
Output is correct |
44 |
Correct |
18 ms |
2732 KB |
Output is correct |
45 |
Correct |
17 ms |
2712 KB |
Output is correct |
46 |
Correct |
17 ms |
2736 KB |
Output is correct |
47 |
Correct |
16 ms |
2740 KB |
Output is correct |
48 |
Correct |
16 ms |
2728 KB |
Output is correct |
49 |
Correct |
17 ms |
2764 KB |
Output is correct |
50 |
Execution timed out |
1091 ms |
46540 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |