# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
473730 | 2021-09-16T02:41:30 Z | Lam_lai_cuoc_doi | Bigger segments (IZhO19_segments) | C++17 | 98 ms | 12920 KB |
#define task "PARTITION" #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; using ll = long long; using ld = long double; template <class T> void read(T &x) { x = 0; register int c; while ((c = getchar()) && (c > '9' || c < '0')) ; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; } constexpr int N = 5e5 + 5; constexpr int Inf = 1e9 + 7; int n, pre[N], ans[N]; ll a[N]; void Read() { cin >> n; //read(n); for (int i = 1; i <= n; ++i) cin >> a[i]; //read(a[i]); //reverse(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) a[i] += a[i - 1]; } void Sub_1() { vector<vector<int>> dp(n + 5, vector<int>(n + 5, -Inf)); dp[0][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = i - 1, t = i - 2; j >= 0; --j) { if (t >= j) --t; while (t >= 0 && a[i] - a[j] >= a[j] - a[t]) --t; dp[i][j] = max(dp[i][j + 1], dp[j][t + 1] + 1); } } cout << dp[n][0]; } void Greedy() { for (int i = 1; i <= n; ++i) { pre[i] = max(pre[i], pre[i - 1]); ans[i] = ans[pre[i]] + 1; int j = lower_bound(a + 1, a + n + 1, a[i] * 2 - a[pre[i]]) - a; pre[j] = max(pre[j], i); } cout << ans[n]; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } Read(); if (n <= 1000) Sub_1(); else Greedy(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 316 KB | Output is correct |
6 | Correct | 1 ms | 292 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 | 324 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 320 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 316 KB | Output is correct |
6 | Correct | 1 ms | 292 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 | 324 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 320 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 2 ms | 1228 KB | Output is correct |
17 | Correct | 2 ms | 1228 KB | Output is correct |
18 | Correct | 2 ms | 1228 KB | Output is correct |
19 | Correct | 2 ms | 1228 KB | Output is correct |
20 | Correct | 2 ms | 1228 KB | Output is correct |
21 | Correct | 2 ms | 1228 KB | Output is correct |
22 | Correct | 2 ms | 972 KB | Output is correct |
23 | Correct | 1 ms | 588 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 2 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1228 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 316 KB | Output is correct |
6 | Correct | 1 ms | 292 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 | 324 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 320 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 2 ms | 1228 KB | Output is correct |
17 | Correct | 2 ms | 1228 KB | Output is correct |
18 | Correct | 2 ms | 1228 KB | Output is correct |
19 | Correct | 2 ms | 1228 KB | Output is correct |
20 | Correct | 2 ms | 1228 KB | Output is correct |
21 | Correct | 2 ms | 1228 KB | Output is correct |
22 | Correct | 2 ms | 972 KB | Output is correct |
23 | Correct | 1 ms | 588 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 2 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1228 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 1 ms | 332 KB | Output is correct |
36 | Correct | 1 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 332 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 332 KB | Output is correct |
40 | Correct | 1 ms | 332 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
42 | Correct | 1 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 324 KB | Output is correct |
44 | Correct | 1 ms | 332 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 316 KB | Output is correct |
6 | Correct | 1 ms | 292 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 | 324 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 320 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 2 ms | 1228 KB | Output is correct |
17 | Correct | 2 ms | 1228 KB | Output is correct |
18 | Correct | 2 ms | 1228 KB | Output is correct |
19 | Correct | 2 ms | 1228 KB | Output is correct |
20 | Correct | 2 ms | 1228 KB | Output is correct |
21 | Correct | 2 ms | 1228 KB | Output is correct |
22 | Correct | 2 ms | 972 KB | Output is correct |
23 | Correct | 1 ms | 588 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 2 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1228 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 1 ms | 332 KB | Output is correct |
36 | Correct | 1 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 332 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 332 KB | Output is correct |
40 | Correct | 1 ms | 332 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
42 | Correct | 1 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 324 KB | Output is correct |
44 | Correct | 1 ms | 332 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
46 | Correct | 12 ms | 2252 KB | Output is correct |
47 | Correct | 17 ms | 2252 KB | Output is correct |
48 | Correct | 19 ms | 2688 KB | Output is correct |
49 | Correct | 19 ms | 2764 KB | Output is correct |
50 | Correct | 21 ms | 2868 KB | Output is correct |
51 | Correct | 19 ms | 2764 KB | Output is correct |
52 | Correct | 10 ms | 1492 KB | Output is correct |
53 | Correct | 6 ms | 1100 KB | Output is correct |
54 | Correct | 14 ms | 1996 KB | Output is correct |
55 | Correct | 19 ms | 2748 KB | Output is correct |
56 | Correct | 16 ms | 2268 KB | Output is correct |
57 | Correct | 14 ms | 2252 KB | Output is correct |
58 | Correct | 15 ms | 2284 KB | Output is correct |
59 | Correct | 17 ms | 2392 KB | Output is correct |
60 | Correct | 17 ms | 2380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 316 KB | Output is correct |
6 | Correct | 1 ms | 292 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 | 324 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 320 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 2 ms | 1228 KB | Output is correct |
17 | Correct | 2 ms | 1228 KB | Output is correct |
18 | Correct | 2 ms | 1228 KB | Output is correct |
19 | Correct | 2 ms | 1228 KB | Output is correct |
20 | Correct | 2 ms | 1228 KB | Output is correct |
21 | Correct | 2 ms | 1228 KB | Output is correct |
22 | Correct | 2 ms | 972 KB | Output is correct |
23 | Correct | 1 ms | 588 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 2 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1228 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 1 ms | 332 KB | Output is correct |
36 | Correct | 1 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 332 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 332 KB | Output is correct |
40 | Correct | 1 ms | 332 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
42 | Correct | 1 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 324 KB | Output is correct |
44 | Correct | 1 ms | 332 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
46 | Correct | 12 ms | 2252 KB | Output is correct |
47 | Correct | 17 ms | 2252 KB | Output is correct |
48 | Correct | 19 ms | 2688 KB | Output is correct |
49 | Correct | 19 ms | 2764 KB | Output is correct |
50 | Correct | 21 ms | 2868 KB | Output is correct |
51 | Correct | 19 ms | 2764 KB | Output is correct |
52 | Correct | 10 ms | 1492 KB | Output is correct |
53 | Correct | 6 ms | 1100 KB | Output is correct |
54 | Correct | 14 ms | 1996 KB | Output is correct |
55 | Correct | 19 ms | 2748 KB | Output is correct |
56 | Correct | 16 ms | 2268 KB | Output is correct |
57 | Correct | 14 ms | 2252 KB | Output is correct |
58 | Correct | 15 ms | 2284 KB | Output is correct |
59 | Correct | 17 ms | 2392 KB | Output is correct |
60 | Correct | 17 ms | 2380 KB | Output is correct |
61 | Correct | 60 ms | 10040 KB | Output is correct |
62 | Correct | 62 ms | 10072 KB | Output is correct |
63 | Correct | 73 ms | 10436 KB | Output is correct |
64 | Correct | 96 ms | 12612 KB | Output is correct |
65 | Correct | 98 ms | 12912 KB | Output is correct |
66 | Correct | 97 ms | 12848 KB | Output is correct |
67 | Correct | 75 ms | 10492 KB | Output is correct |
68 | Correct | 39 ms | 5312 KB | Output is correct |
69 | Correct | 69 ms | 9164 KB | Output is correct |
70 | Correct | 95 ms | 12920 KB | Output is correct |
71 | Correct | 75 ms | 10052 KB | Output is correct |
72 | Correct | 70 ms | 10436 KB | Output is correct |
73 | Correct | 79 ms | 11060 KB | Output is correct |
74 | Correct | 84 ms | 11380 KB | Output is correct |
75 | Correct | 84 ms | 11376 KB | Output is correct |