답안 #345632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345632 2021-01-07T17:26:32 Z maskoff Bigger segments (IZhO19_segments) C++14
100 / 100
115 ms 24416 KB
	#include <bits/stdc++.h>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
const ll inf = 1e18 + 5;
const ll mod = 1e9 + 7;
 
const int N = 5e5 + 5;
 
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, +1, 0, -1};

ll p[N], a[N];
ll n;
vector<pair<ll, ll>> dp(N + 5), all;

int get(ll x) {
	int l = 0;
	int r = all.size() - 1;
	int ans = -1;
	while (l <= r) {
	 	int m = l + r >> 1;
	 	if (all[m].fr <= x) l = m + 1, ans = m;
		else r = m - 1;
	}
	if (ans == -1) return 0;
	return all[ans].sc;
}
 	

int main() {  
	ios_base :: sync_with_stdio(false);               
	cin.tie(nullptr);                                               
	srand(time(nullptr));
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];

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

	for (int i = 1; i <= n; i++) {
	 	int pos = get(p[i]);
	 	//cerr << i << " " << pos << endl;
	 	dp[i].fr = dp[pos].fr + 1;
	 	dp[i].sc = p[i] - p[pos];
		while ((int)all.size() > 0 && all.back().fr >= dp[i].sc + p[i]) 
		 	all.pop_back();
		all.pb({dp[i].sc + p[i], i});
		/*for (auto t : all)
			cout << t.fr << " ";
		cout << endl; */
	}         

	/*for (int i = 1; i <= n; i++) 
	 	cout << i << ": " << dp[i].fr << " " << dp[i].sc << endl;  */
	cout << dp[n].fr;
  return 0;                   
}  

Compilation message

segments.cpp: In function 'int get(ll)':
segments.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |    int m = l + r >> 1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8172 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 4 ms 8192 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 5 ms 8172 KB Output is correct
7 Correct 4 ms 8172 KB Output is correct
8 Correct 4 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 5 ms 8172 KB Output is correct
12 Correct 4 ms 8172 KB Output is correct
13 Correct 4 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 4 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8172 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 4 ms 8192 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 5 ms 8172 KB Output is correct
7 Correct 4 ms 8172 KB Output is correct
8 Correct 4 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 5 ms 8172 KB Output is correct
12 Correct 4 ms 8172 KB Output is correct
13 Correct 4 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 4 ms 8172 KB Output is correct
16 Correct 4 ms 8172 KB Output is correct
17 Correct 4 ms 8172 KB Output is correct
18 Correct 4 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 4 ms 8172 KB Output is correct
22 Correct 5 ms 8172 KB Output is correct
23 Correct 4 ms 8172 KB Output is correct
24 Correct 5 ms 8172 KB Output is correct
25 Correct 5 ms 8172 KB Output is correct
26 Correct 5 ms 8172 KB Output is correct
27 Correct 5 ms 8172 KB Output is correct
28 Correct 5 ms 8172 KB Output is correct
29 Correct 5 ms 8172 KB Output is correct
30 Correct 5 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8172 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 4 ms 8192 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 5 ms 8172 KB Output is correct
7 Correct 4 ms 8172 KB Output is correct
8 Correct 4 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 5 ms 8172 KB Output is correct
12 Correct 4 ms 8172 KB Output is correct
13 Correct 4 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 4 ms 8172 KB Output is correct
16 Correct 4 ms 8172 KB Output is correct
17 Correct 4 ms 8172 KB Output is correct
18 Correct 4 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 4 ms 8172 KB Output is correct
22 Correct 5 ms 8172 KB Output is correct
23 Correct 4 ms 8172 KB Output is correct
24 Correct 5 ms 8172 KB Output is correct
25 Correct 5 ms 8172 KB Output is correct
26 Correct 5 ms 8172 KB Output is correct
27 Correct 5 ms 8172 KB Output is correct
28 Correct 5 ms 8172 KB Output is correct
29 Correct 5 ms 8172 KB Output is correct
30 Correct 5 ms 8172 KB Output is correct
31 Correct 5 ms 8300 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 5 ms 8172 KB Output is correct
34 Correct 5 ms 8300 KB Output is correct
35 Correct 5 ms 8300 KB Output is correct
36 Correct 5 ms 8300 KB Output is correct
37 Correct 5 ms 8300 KB Output is correct
38 Correct 5 ms 8300 KB Output is correct
39 Correct 5 ms 8300 KB Output is correct
40 Correct 5 ms 8300 KB Output is correct
41 Correct 5 ms 8300 KB Output is correct
42 Correct 5 ms 8300 KB Output is correct
43 Correct 5 ms 8300 KB Output is correct
44 Correct 5 ms 8300 KB Output is correct
45 Correct 5 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8172 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 4 ms 8192 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 5 ms 8172 KB Output is correct
7 Correct 4 ms 8172 KB Output is correct
8 Correct 4 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 5 ms 8172 KB Output is correct
12 Correct 4 ms 8172 KB Output is correct
13 Correct 4 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 4 ms 8172 KB Output is correct
16 Correct 4 ms 8172 KB Output is correct
17 Correct 4 ms 8172 KB Output is correct
18 Correct 4 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 4 ms 8172 KB Output is correct
22 Correct 5 ms 8172 KB Output is correct
23 Correct 4 ms 8172 KB Output is correct
24 Correct 5 ms 8172 KB Output is correct
25 Correct 5 ms 8172 KB Output is correct
26 Correct 5 ms 8172 KB Output is correct
27 Correct 5 ms 8172 KB Output is correct
28 Correct 5 ms 8172 KB Output is correct
29 Correct 5 ms 8172 KB Output is correct
30 Correct 5 ms 8172 KB Output is correct
31 Correct 5 ms 8300 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 5 ms 8172 KB Output is correct
34 Correct 5 ms 8300 KB Output is correct
35 Correct 5 ms 8300 KB Output is correct
36 Correct 5 ms 8300 KB Output is correct
37 Correct 5 ms 8300 KB Output is correct
38 Correct 5 ms 8300 KB Output is correct
39 Correct 5 ms 8300 KB Output is correct
40 Correct 5 ms 8300 KB Output is correct
41 Correct 5 ms 8300 KB Output is correct
42 Correct 5 ms 8300 KB Output is correct
43 Correct 5 ms 8300 KB Output is correct
44 Correct 5 ms 8300 KB Output is correct
45 Correct 5 ms 8300 KB Output is correct
46 Correct 16 ms 11880 KB Output is correct
47 Correct 19 ms 11880 KB Output is correct
48 Correct 18 ms 9964 KB Output is correct
49 Correct 20 ms 10860 KB Output is correct
50 Correct 24 ms 11880 KB Output is correct
51 Correct 22 ms 11880 KB Output is correct
52 Correct 13 ms 10092 KB Output is correct
53 Correct 10 ms 9328 KB Output is correct
54 Correct 17 ms 11880 KB Output is correct
55 Correct 21 ms 11880 KB Output is correct
56 Correct 17 ms 11880 KB Output is correct
57 Correct 18 ms 11900 KB Output is correct
58 Correct 18 ms 11880 KB Output is correct
59 Correct 18 ms 11880 KB Output is correct
60 Correct 18 ms 11880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8172 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 4 ms 8192 KB Output is correct
5 Correct 6 ms 8172 KB Output is correct
6 Correct 5 ms 8172 KB Output is correct
7 Correct 4 ms 8172 KB Output is correct
8 Correct 4 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 5 ms 8172 KB Output is correct
12 Correct 4 ms 8172 KB Output is correct
13 Correct 4 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 4 ms 8172 KB Output is correct
16 Correct 4 ms 8172 KB Output is correct
17 Correct 4 ms 8172 KB Output is correct
18 Correct 4 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 4 ms 8172 KB Output is correct
22 Correct 5 ms 8172 KB Output is correct
23 Correct 4 ms 8172 KB Output is correct
24 Correct 5 ms 8172 KB Output is correct
25 Correct 5 ms 8172 KB Output is correct
26 Correct 5 ms 8172 KB Output is correct
27 Correct 5 ms 8172 KB Output is correct
28 Correct 5 ms 8172 KB Output is correct
29 Correct 5 ms 8172 KB Output is correct
30 Correct 5 ms 8172 KB Output is correct
31 Correct 5 ms 8300 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 5 ms 8172 KB Output is correct
34 Correct 5 ms 8300 KB Output is correct
35 Correct 5 ms 8300 KB Output is correct
36 Correct 5 ms 8300 KB Output is correct
37 Correct 5 ms 8300 KB Output is correct
38 Correct 5 ms 8300 KB Output is correct
39 Correct 5 ms 8300 KB Output is correct
40 Correct 5 ms 8300 KB Output is correct
41 Correct 5 ms 8300 KB Output is correct
42 Correct 5 ms 8300 KB Output is correct
43 Correct 5 ms 8300 KB Output is correct
44 Correct 5 ms 8300 KB Output is correct
45 Correct 5 ms 8300 KB Output is correct
46 Correct 16 ms 11880 KB Output is correct
47 Correct 19 ms 11880 KB Output is correct
48 Correct 18 ms 9964 KB Output is correct
49 Correct 20 ms 10860 KB Output is correct
50 Correct 24 ms 11880 KB Output is correct
51 Correct 22 ms 11880 KB Output is correct
52 Correct 13 ms 10092 KB Output is correct
53 Correct 10 ms 9328 KB Output is correct
54 Correct 17 ms 11880 KB Output is correct
55 Correct 21 ms 11880 KB Output is correct
56 Correct 17 ms 11880 KB Output is correct
57 Correct 18 ms 11900 KB Output is correct
58 Correct 18 ms 11880 KB Output is correct
59 Correct 18 ms 11880 KB Output is correct
60 Correct 18 ms 11880 KB Output is correct
61 Correct 65 ms 24288 KB Output is correct
62 Correct 72 ms 24308 KB Output is correct
63 Correct 77 ms 24288 KB Output is correct
64 Correct 92 ms 18200 KB Output is correct
65 Correct 89 ms 24288 KB Output is correct
66 Correct 115 ms 24288 KB Output is correct
67 Correct 79 ms 22752 KB Output is correct
68 Correct 41 ms 15588 KB Output is correct
69 Correct 70 ms 24288 KB Output is correct
70 Correct 96 ms 24416 KB Output is correct
71 Correct 70 ms 24308 KB Output is correct
72 Correct 79 ms 24288 KB Output is correct
73 Correct 81 ms 24416 KB Output is correct
74 Correct 76 ms 24288 KB Output is correct
75 Correct 85 ms 24288 KB Output is correct