# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497934 | 2021-12-24T05:06:02 Z | Ziel | Bigger segments (IZhO19_segments) | C++17 | 69 ms | 15968 KB |
/** * LES GREATEABLES BRO TEAM **/ #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)x.size() const bool FLAG = false; void setIO(const string &f = ""); #define int ll const int N = 5e5 + 137; ll a[N], dp[N], last[N], pref[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = a[i]; pref[i] += pref[i - 1]; } dp[1] = 1; last[1] = 1; for (int j = 1; j <= n; j++) { int right = 2 * pref[j] - pref[last[j] - 1]; int lo = j, hi = n, res = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (pref[mid] >= right) { res = mid; hi = mid - 1; } else lo = mid + 1; } if (res != -1) { if (dp[res] <= dp[j] + 1) { dp[res] = dp[j] + 1; last[res] = j + 1; } } if (dp[j + 1] < dp[j]) { dp[j + 1] = dp[j]; last[j + 1] = last[j]; } else if (dp[j + 1] == dp[j] && last[j] > last[j + 1]) { dp[j + 1] = dp[j]; last[j + 1] = last[j]; } } cout << dp[n]; } signed main() { setIO(); int tt = 1; if (FLAG) { cin >> tt; } while (tt--) { solve(); } return 0; } void setIO(const string &f) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen((f + ".in").c_str(), "r")) { freopen((f + ".in").c_str(), "r", stdin); freopen((f + ".out").c_str(), "w", stdout); } }
Compilation message
# | 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 | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 332 KB | Output is correct |
9 | Correct | 0 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 0 ms | 332 KB | Output is correct |
15 | 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 | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 332 KB | Output is correct |
9 | Correct | 0 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 0 ms | 332 KB | Output is correct |
15 | Correct | 0 ms | 332 KB | Output is correct |
16 | Correct | 0 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 0 ms | 332 KB | Output is correct |
20 | Correct | 0 ms | 332 KB | Output is correct |
21 | Correct | 0 ms | 332 KB | Output is correct |
22 | Correct | 0 ms | 332 KB | Output is correct |
23 | Correct | 0 ms | 332 KB | Output is correct |
24 | Correct | 0 ms | 332 KB | Output is correct |
25 | Correct | 0 ms | 332 KB | Output is correct |
26 | Correct | 0 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 0 ms | 332 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | 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 | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 332 KB | Output is correct |
9 | Correct | 0 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 0 ms | 332 KB | Output is correct |
15 | Correct | 0 ms | 332 KB | Output is correct |
16 | Correct | 0 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 0 ms | 332 KB | Output is correct |
20 | Correct | 0 ms | 332 KB | Output is correct |
21 | Correct | 0 ms | 332 KB | Output is correct |
22 | Correct | 0 ms | 332 KB | Output is correct |
23 | Correct | 0 ms | 332 KB | Output is correct |
24 | Correct | 0 ms | 332 KB | Output is correct |
25 | Correct | 0 ms | 332 KB | Output is correct |
26 | Correct | 0 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 0 ms | 332 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | Correct | 0 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 2 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 | 2 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 | 0 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 332 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 | 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 | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 332 KB | Output is correct |
9 | Correct | 0 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 0 ms | 332 KB | Output is correct |
15 | Correct | 0 ms | 332 KB | Output is correct |
16 | Correct | 0 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 0 ms | 332 KB | Output is correct |
20 | Correct | 0 ms | 332 KB | Output is correct |
21 | Correct | 0 ms | 332 KB | Output is correct |
22 | Correct | 0 ms | 332 KB | Output is correct |
23 | Correct | 0 ms | 332 KB | Output is correct |
24 | Correct | 0 ms | 332 KB | Output is correct |
25 | Correct | 0 ms | 332 KB | Output is correct |
26 | Correct | 0 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 0 ms | 332 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | Correct | 0 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 2 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 | 2 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 | 0 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 332 KB | Output is correct |
44 | Correct | 1 ms | 332 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
46 | Correct | 8 ms | 3456 KB | Output is correct |
47 | Correct | 12 ms | 3372 KB | Output is correct |
48 | Correct | 17 ms | 3388 KB | Output is correct |
49 | Correct | 12 ms | 3372 KB | Output is correct |
50 | Correct | 13 ms | 3444 KB | Output is correct |
51 | Correct | 13 ms | 3480 KB | Output is correct |
52 | Correct | 9 ms | 1892 KB | Output is correct |
53 | Correct | 4 ms | 1228 KB | Output is correct |
54 | Correct | 10 ms | 3408 KB | Output is correct |
55 | Correct | 13 ms | 3400 KB | Output is correct |
56 | Correct | 12 ms | 3428 KB | Output is correct |
57 | Correct | 9 ms | 3404 KB | Output is correct |
58 | Correct | 10 ms | 3372 KB | Output is correct |
59 | Correct | 11 ms | 3388 KB | Output is correct |
60 | Correct | 9 ms | 3404 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 | 0 ms | 332 KB | Output is correct |
8 | Correct | 0 ms | 332 KB | Output is correct |
9 | Correct | 0 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 0 ms | 332 KB | Output is correct |
12 | Correct | 0 ms | 332 KB | Output is correct |
13 | Correct | 0 ms | 332 KB | Output is correct |
14 | Correct | 0 ms | 332 KB | Output is correct |
15 | Correct | 0 ms | 332 KB | Output is correct |
16 | Correct | 0 ms | 332 KB | Output is correct |
17 | Correct | 0 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 0 ms | 332 KB | Output is correct |
20 | Correct | 0 ms | 332 KB | Output is correct |
21 | Correct | 0 ms | 332 KB | Output is correct |
22 | Correct | 0 ms | 332 KB | Output is correct |
23 | Correct | 0 ms | 332 KB | Output is correct |
24 | Correct | 0 ms | 332 KB | Output is correct |
25 | Correct | 0 ms | 332 KB | Output is correct |
26 | Correct | 0 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 0 ms | 332 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | Correct | 0 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 2 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 | 2 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 | 0 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 332 KB | Output is correct |
44 | Correct | 1 ms | 332 KB | Output is correct |
45 | Correct | 1 ms | 332 KB | Output is correct |
46 | Correct | 8 ms | 3456 KB | Output is correct |
47 | Correct | 12 ms | 3372 KB | Output is correct |
48 | Correct | 17 ms | 3388 KB | Output is correct |
49 | Correct | 12 ms | 3372 KB | Output is correct |
50 | Correct | 13 ms | 3444 KB | Output is correct |
51 | Correct | 13 ms | 3480 KB | Output is correct |
52 | Correct | 9 ms | 1892 KB | Output is correct |
53 | Correct | 4 ms | 1228 KB | Output is correct |
54 | Correct | 10 ms | 3408 KB | Output is correct |
55 | Correct | 13 ms | 3400 KB | Output is correct |
56 | Correct | 12 ms | 3428 KB | Output is correct |
57 | Correct | 9 ms | 3404 KB | Output is correct |
58 | Correct | 10 ms | 3372 KB | Output is correct |
59 | Correct | 11 ms | 3388 KB | Output is correct |
60 | Correct | 9 ms | 3404 KB | Output is correct |
61 | Correct | 43 ms | 15908 KB | Output is correct |
62 | Correct | 62 ms | 15936 KB | Output is correct |
63 | Correct | 62 ms | 15840 KB | Output is correct |
64 | Correct | 69 ms | 15968 KB | Output is correct |
65 | Correct | 58 ms | 15876 KB | Output is correct |
66 | Correct | 68 ms | 15912 KB | Output is correct |
67 | Correct | 59 ms | 12844 KB | Output is correct |
68 | Correct | 29 ms | 6528 KB | Output is correct |
69 | Correct | 52 ms | 15892 KB | Output is correct |
70 | Correct | 68 ms | 15884 KB | Output is correct |
71 | Correct | 42 ms | 15840 KB | Output is correct |
72 | Correct | 62 ms | 15920 KB | Output is correct |
73 | Correct | 50 ms | 15960 KB | Output is correct |
74 | Correct | 50 ms | 15940 KB | Output is correct |
75 | Correct | 67 ms | 15920 KB | Output is correct |