답안 #1114007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114007 2024-11-18T05:43:44 Z stdfloat Bigger segments (IZhO19_segments) C++17
100 / 100
219 ms 34632 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

vector<ll> st;

int fnd(int nd, int l, int r, int x, int y, ll vl) {
	if (r < x || y < l || vl < st[nd]) return -1;

	if (l == r) return l;

	int ch = nd << 1, md = (l + r) >> 1, res = fnd(ch + 1, md + 1, r, x, y, vl);
	return (~res ? res : fnd(ch, l, md, x, y, vl));	
}

ll upd(int nd, int l, int r, int x, ll vl) {
	if (r < x || x < l) return st[nd];

	if (l == r) return st[nd] = vl;

	int ch = nd << 1, md = (l + r) >> 1;
	return st[nd] = min(upd(ch, l, md, x, vl), upd(ch + 1, md + 1, r, x, vl)); 
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	cin >> n;

	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	vector<ll> p(n + 1);
	for (int i = 1; i <= n; i++)
		p[i] = p[i - 1] + a[i];

	st.assign(n << 2, 0);
	vector<ll> dp(n + 1), v(n + 1);
	for (int i = 1; i <= n; i++) {
		int x = fnd(1, 0, n, 0, i - 1, p[i]);

		dp[i] = dp[x] + 1;
		upd(1, 0, n, i, (p[i] << 1) - p[x]);
	}

	cout << dp[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 564 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 564 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 564 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 760 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 564 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 760 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 33 ms 6480 KB Output is correct
47 Correct 34 ms 6748 KB Output is correct
48 Correct 33 ms 6992 KB Output is correct
49 Correct 35 ms 7248 KB Output is correct
50 Correct 33 ms 7248 KB Output is correct
51 Correct 37 ms 7248 KB Output is correct
52 Correct 19 ms 3664 KB Output is correct
53 Correct 12 ms 2384 KB Output is correct
54 Correct 35 ms 6480 KB Output is correct
55 Correct 37 ms 7248 KB Output is correct
56 Correct 29 ms 6736 KB Output is correct
57 Correct 31 ms 6736 KB Output is correct
58 Correct 34 ms 6736 KB Output is correct
59 Correct 34 ms 6924 KB Output is correct
60 Correct 33 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 564 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 760 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 33 ms 6480 KB Output is correct
47 Correct 34 ms 6748 KB Output is correct
48 Correct 33 ms 6992 KB Output is correct
49 Correct 35 ms 7248 KB Output is correct
50 Correct 33 ms 7248 KB Output is correct
51 Correct 37 ms 7248 KB Output is correct
52 Correct 19 ms 3664 KB Output is correct
53 Correct 12 ms 2384 KB Output is correct
54 Correct 35 ms 6480 KB Output is correct
55 Correct 37 ms 7248 KB Output is correct
56 Correct 29 ms 6736 KB Output is correct
57 Correct 31 ms 6736 KB Output is correct
58 Correct 34 ms 6736 KB Output is correct
59 Correct 34 ms 6924 KB Output is correct
60 Correct 33 ms 6736 KB Output is correct
61 Correct 181 ms 31704 KB Output is correct
62 Correct 179 ms 31560 KB Output is correct
63 Correct 207 ms 32072 KB Output is correct
64 Correct 206 ms 34268 KB Output is correct
65 Correct 176 ms 34632 KB Output is correct
66 Correct 207 ms 34632 KB Output is correct
67 Correct 160 ms 27600 KB Output is correct
68 Correct 79 ms 13896 KB Output is correct
69 Correct 190 ms 30792 KB Output is correct
70 Correct 219 ms 34632 KB Output is correct
71 Correct 162 ms 31560 KB Output is correct
72 Correct 169 ms 32072 KB Output is correct
73 Correct 177 ms 32604 KB Output is correct
74 Correct 176 ms 33096 KB Output is correct
75 Correct 171 ms 33100 KB Output is correct