#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <unordered_map>
const int BULAN = 169;
int x;
int arr[500005];
int64_t pfx[500005];
std::unordered_map<int64_t,std::unordered_map<int,int>> memo;
inline int64_t sum_query(int l, int r) {
return pfx[r] - pfx[l-1];
}
int solve(int64_t cap, int pos = x) {
if (memo.count(cap)&&memo[cap].count(pos)) {
return memo[cap][pos];
}
if (pos==0) {
return 0;
}
if (arr[pos]>cap) {
return -0x3f3f3f3f;
}
int i = pos+1;
int64_t sum = 0;
int ret = -0x3f3f3f3f;
int cnt = 0;
while (i-1>=1&&sum+arr[i-1]<=cap) {
--i;
sum += arr[i];
++cnt;
if (cnt<=BULAN) {
ret = std::max(ret,1+solve(sum,i-1));
}
}
ret = std::max(ret,1+solve(sum,i-1));
return memo[cap][pos] = ret;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> x;
for (int i = 1; i <= x; i++) {
std::cin >> arr[i];
pfx[i] = pfx[i-1] + arr[i];
}
/*for (int cap = 1; cap <= 50; cap++) {
std::cout << cap << " " << solve(cap) << "\n";
}*/
const auto bs = [&]() {
int ret = 1;
int64_t l = 1, r = 1000000000000000000;
while (l<=r) {
int64_t m = (l+r)/2;
int tmp = solve(m);
if (tmp!=-0x3f3f3f3f) {
ret = std::max(ret,tmp);
r = m-1;
}
else {
l = m+1;
}
}
return ret;
};
std::cout << bs() << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
89 ms |
2580 KB |
Output is correct |
17 |
Correct |
108 ms |
8680 KB |
Output is correct |
18 |
Correct |
130 ms |
9388 KB |
Output is correct |
19 |
Correct |
16 ms |
1624 KB |
Output is correct |
20 |
Correct |
92 ms |
2384 KB |
Output is correct |
21 |
Correct |
171 ms |
11292 KB |
Output is correct |
22 |
Correct |
89 ms |
7856 KB |
Output is correct |
23 |
Correct |
47 ms |
5076 KB |
Output is correct |
24 |
Correct |
119 ms |
2460 KB |
Output is correct |
25 |
Correct |
166 ms |
11404 KB |
Output is correct |
26 |
Correct |
164 ms |
4692 KB |
Output is correct |
27 |
Correct |
95 ms |
2856 KB |
Output is correct |
28 |
Correct |
159 ms |
3924 KB |
Output is correct |
29 |
Correct |
314 ms |
7132 KB |
Output is correct |
30 |
Correct |
62 ms |
4416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
89 ms |
2580 KB |
Output is correct |
17 |
Correct |
108 ms |
8680 KB |
Output is correct |
18 |
Correct |
130 ms |
9388 KB |
Output is correct |
19 |
Correct |
16 ms |
1624 KB |
Output is correct |
20 |
Correct |
92 ms |
2384 KB |
Output is correct |
21 |
Correct |
171 ms |
11292 KB |
Output is correct |
22 |
Correct |
89 ms |
7856 KB |
Output is correct |
23 |
Correct |
47 ms |
5076 KB |
Output is correct |
24 |
Correct |
119 ms |
2460 KB |
Output is correct |
25 |
Correct |
166 ms |
11404 KB |
Output is correct |
26 |
Correct |
164 ms |
4692 KB |
Output is correct |
27 |
Correct |
95 ms |
2856 KB |
Output is correct |
28 |
Correct |
159 ms |
3924 KB |
Output is correct |
29 |
Correct |
314 ms |
7132 KB |
Output is correct |
30 |
Correct |
62 ms |
4416 KB |
Output is correct |
31 |
Execution timed out |
1583 ms |
19652 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
89 ms |
2580 KB |
Output is correct |
17 |
Correct |
108 ms |
8680 KB |
Output is correct |
18 |
Correct |
130 ms |
9388 KB |
Output is correct |
19 |
Correct |
16 ms |
1624 KB |
Output is correct |
20 |
Correct |
92 ms |
2384 KB |
Output is correct |
21 |
Correct |
171 ms |
11292 KB |
Output is correct |
22 |
Correct |
89 ms |
7856 KB |
Output is correct |
23 |
Correct |
47 ms |
5076 KB |
Output is correct |
24 |
Correct |
119 ms |
2460 KB |
Output is correct |
25 |
Correct |
166 ms |
11404 KB |
Output is correct |
26 |
Correct |
164 ms |
4692 KB |
Output is correct |
27 |
Correct |
95 ms |
2856 KB |
Output is correct |
28 |
Correct |
159 ms |
3924 KB |
Output is correct |
29 |
Correct |
314 ms |
7132 KB |
Output is correct |
30 |
Correct |
62 ms |
4416 KB |
Output is correct |
31 |
Execution timed out |
1583 ms |
19652 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
89 ms |
2580 KB |
Output is correct |
17 |
Correct |
108 ms |
8680 KB |
Output is correct |
18 |
Correct |
130 ms |
9388 KB |
Output is correct |
19 |
Correct |
16 ms |
1624 KB |
Output is correct |
20 |
Correct |
92 ms |
2384 KB |
Output is correct |
21 |
Correct |
171 ms |
11292 KB |
Output is correct |
22 |
Correct |
89 ms |
7856 KB |
Output is correct |
23 |
Correct |
47 ms |
5076 KB |
Output is correct |
24 |
Correct |
119 ms |
2460 KB |
Output is correct |
25 |
Correct |
166 ms |
11404 KB |
Output is correct |
26 |
Correct |
164 ms |
4692 KB |
Output is correct |
27 |
Correct |
95 ms |
2856 KB |
Output is correct |
28 |
Correct |
159 ms |
3924 KB |
Output is correct |
29 |
Correct |
314 ms |
7132 KB |
Output is correct |
30 |
Correct |
62 ms |
4416 KB |
Output is correct |
31 |
Execution timed out |
1583 ms |
19652 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |