Submission #536683

# Submission time Handle Problem Language Result Execution time Memory
536683 2022-03-13T20:19:53 Z blue Bigger segments (IZhO19_segments) C++17
100 / 100
201 ms 45340 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N;
	cin >> N;

	ll Asum[1+N];
	Asum[0] = 0;
	for(int i = 1; i <= N; i++)
	{
		cin >> Asum[i];
		Asum[i] += Asum[i-1];
	}

	pll DP[1+N];
	DP[0] = {0, 0};

	set<pll> tbv;

	pll currbest{0, 0};

	for(int i = 1; i <= N; i++)
	{
		// cerr << "\n\n\ni = " << i << '\n';
		tbv.insert({DP[i-1].second + Asum[i-1], i-1});
		// cerr << "tbv insert " << DP[i-1].second + Asum[i-1] << ' ' << i-1 << '\n';

		// cerr << tbv.begin()->first << '\n';

		while(!tbv.empty() && tbv.begin()->first <= Asum[i])
		{
			currbest = max(currbest, {DP[tbv.begin()->second].first, tbv.begin()->second});
			// cerr << "tbv erase " << tbv.begin()->first << ' ' << tbv.begin()->second << '\n';
			tbv.erase(tbv.begin());
		}

		DP[i] = {currbest.first + 1, Asum[i] - Asum[currbest.second]};

		// cerr << i << " : " << DP[i].first << ' ' << DP[i].second << '\n';
	}

	cout << DP[N].first << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 29 ms 9268 KB Output is correct
47 Correct 21 ms 3628 KB Output is correct
48 Correct 20 ms 3532 KB Output is correct
49 Correct 20 ms 4100 KB Output is correct
50 Correct 15 ms 3608 KB Output is correct
51 Correct 23 ms 3640 KB Output is correct
52 Correct 17 ms 1876 KB Output is correct
53 Correct 7 ms 1236 KB Output is correct
54 Correct 18 ms 2888 KB Output is correct
55 Correct 24 ms 3644 KB Output is correct
56 Correct 12 ms 3112 KB Output is correct
57 Correct 26 ms 5580 KB Output is correct
58 Correct 16 ms 4664 KB Output is correct
59 Correct 11 ms 3132 KB Output is correct
60 Correct 14 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 324 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 29 ms 9268 KB Output is correct
47 Correct 21 ms 3628 KB Output is correct
48 Correct 20 ms 3532 KB Output is correct
49 Correct 20 ms 4100 KB Output is correct
50 Correct 15 ms 3608 KB Output is correct
51 Correct 23 ms 3640 KB Output is correct
52 Correct 17 ms 1876 KB Output is correct
53 Correct 7 ms 1236 KB Output is correct
54 Correct 18 ms 2888 KB Output is correct
55 Correct 24 ms 3644 KB Output is correct
56 Correct 12 ms 3112 KB Output is correct
57 Correct 26 ms 5580 KB Output is correct
58 Correct 16 ms 4664 KB Output is correct
59 Correct 11 ms 3132 KB Output is correct
60 Correct 14 ms 3196 KB Output is correct
61 Correct 201 ms 45340 KB Output is correct
62 Correct 152 ms 29644 KB Output is correct
63 Correct 130 ms 20336 KB Output is correct
64 Correct 98 ms 16492 KB Output is correct
65 Correct 78 ms 16844 KB Output is correct
66 Correct 136 ms 16932 KB Output is correct
67 Correct 93 ms 13540 KB Output is correct
68 Correct 47 ms 6856 KB Output is correct
69 Correct 85 ms 13100 KB Output is correct
70 Correct 123 ms 16872 KB Output is correct
71 Correct 60 ms 14000 KB Output is correct
72 Correct 102 ms 26908 KB Output is correct
73 Correct 75 ms 19596 KB Output is correct
74 Correct 65 ms 15348 KB Output is correct
75 Correct 74 ms 15364 KB Output is correct