답안 #862336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862336 2023-10-18T04:54:43 Z Halym2007 Bigger segments (IZhO19_segments) C++11
100 / 100
183 ms 29632 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define sz size()
#define pb push_back
using namespace std;
const int N = 5e5 + 5;
ll dp[N], p[N], a[N], val[N];
ll ind;
int main () {
//	freopen("testcase.txt", "r", stdin);
	ll n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		p[i] = a[i] + p[i - 1];
	}
	vector <pair <int, ll>> v;
	for (int i = 1; i <= n; ++i) {
		if (!v.empty()) {
			int jog = -1;
			int l = 0, r = (int)v.sz - 1;
			while (l <= r) {
				int md = (l + r) / 2;
				if (v[md].ss > p[i]) {
					r = md - 1;
				}
				else {
					jog = v[md].ff;
					l = md + 1;
				}
			}
			if (jog == -1) {
				val[i] = p[i];
				dp[i] = 1;
			}
			else {
				val[i] = p[i] - p[jog];
				dp[i] = 1 + dp[jog];
			}
		}
		else {
			dp[i] = dp[i - 1] + 1;
			val[i] = a[i];
		}
		while (!v.empty() and v.back().ss >= val[i] + p[i]) v.pop_back();
		v.pb ({i, val[i] + p[i]});
	}
	cout << dp[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2496 KB Output is correct
11 Correct 1 ms 2748 KB Output is correct
12 Correct 0 ms 2492 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2496 KB Output is correct
11 Correct 1 ms 2748 KB Output is correct
12 Correct 0 ms 2492 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2512 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2496 KB Output is correct
11 Correct 1 ms 2748 KB Output is correct
12 Correct 0 ms 2492 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2512 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 2 ms 2512 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2496 KB Output is correct
11 Correct 1 ms 2748 KB Output is correct
12 Correct 0 ms 2492 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2512 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 2 ms 2512 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 20 ms 14280 KB Output is correct
47 Correct 23 ms 13628 KB Output is correct
48 Correct 28 ms 13136 KB Output is correct
49 Correct 31 ms 14024 KB Output is correct
50 Correct 32 ms 15124 KB Output is correct
51 Correct 34 ms 14396 KB Output is correct
52 Correct 17 ms 8916 KB Output is correct
53 Correct 10 ms 5844 KB Output is correct
54 Correct 18 ms 13516 KB Output is correct
55 Correct 36 ms 14644 KB Output is correct
56 Correct 21 ms 14276 KB Output is correct
57 Correct 22 ms 14028 KB Output is correct
58 Correct 22 ms 14016 KB Output is correct
59 Correct 25 ms 14532 KB Output is correct
60 Correct 25 ms 14276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2496 KB Output is correct
11 Correct 1 ms 2748 KB Output is correct
12 Correct 0 ms 2492 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2512 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 2 ms 2512 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 20 ms 14280 KB Output is correct
47 Correct 23 ms 13628 KB Output is correct
48 Correct 28 ms 13136 KB Output is correct
49 Correct 31 ms 14024 KB Output is correct
50 Correct 32 ms 15124 KB Output is correct
51 Correct 34 ms 14396 KB Output is correct
52 Correct 17 ms 8916 KB Output is correct
53 Correct 10 ms 5844 KB Output is correct
54 Correct 18 ms 13516 KB Output is correct
55 Correct 36 ms 14644 KB Output is correct
56 Correct 21 ms 14276 KB Output is correct
57 Correct 22 ms 14028 KB Output is correct
58 Correct 22 ms 14016 KB Output is correct
59 Correct 25 ms 14532 KB Output is correct
60 Correct 25 ms 14276 KB Output is correct
61 Correct 90 ms 25788 KB Output is correct
62 Correct 96 ms 25900 KB Output is correct
63 Correct 108 ms 26556 KB Output is correct
64 Correct 142 ms 22184 KB Output is correct
65 Correct 153 ms 29120 KB Output is correct
66 Correct 162 ms 29424 KB Output is correct
67 Correct 183 ms 27328 KB Output is correct
68 Correct 65 ms 19904 KB Output is correct
69 Correct 78 ms 25280 KB Output is correct
70 Correct 163 ms 29632 KB Output is correct
71 Correct 92 ms 25796 KB Output is correct
72 Correct 106 ms 26048 KB Output is correct
73 Correct 111 ms 28112 KB Output is correct
74 Correct 128 ms 27324 KB Output is correct
75 Correct 123 ms 27316 KB Output is correct