/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )
/▄/ /█/ /🔥/ /▐/ /▌/ /▀/ /░/ /◐ / choose your own style
***IT'S OUR LONG WAY TO THE OIILLLL***
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/detail/standard_policies.hpp>'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;template <typename T> using ordered_set = tree <T, null_type, less< T >, rb_tree_tag,tree_order_statistics_node_update>;
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
#define pii pair < ll , int >
#define pipii pair< int, pair < int , int > >
#define siz(n) (int)(n.size())
#define TIME 1.0 * clock() / CLOCKS_PER_SEC
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
const int inf=1e9 + 7;
const ll inf18=1e18 + 7;
const int N=1e6 + 7;
const int MN = 2097152;
const int M = 1e9 + 7;
ll dp[3001][3001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(0));
#ifdef Estb_probitie
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
ll pref[n];
pref[0] = a[0];
for (int i = 1; i < n; ++i)
pref[i] = pref[i - 1] + a[i];
for (int i = 0; i < n; ++i)
fill(dp[i], dp[i] + n + 1, 1e17);
dp[0][1] = a[0];
for (int i = 1; i < n; ++i)
{
bool byl = 1;
for (int j = 1; j <= i + 1; ++j)
{
dp[i][j] = min(dp[i][j], a[i] + dp[i - 1][j]);
if (j > 1 && byl)
{
byl = 0;
for (int k = i - 1; k >= 0; --k)
if (pref[i] - pref[k] >= dp[k][j - 1])
{
dp[i][j] = min(dp[i][j], pref[i] - pref[k]);
byl = 1;
// cout<<i<<" "<<k<<endl;
break;
}
// cout<<endl;
}
if (dp[i][j] >= 1e17) break;
}
// if (i % 100 == 0)
// cerr<<"i = "<<i<<endl;
// cout<<endl;
}
int ans = 0;
for (int j = 1; j <= n; ++j)
if (dp[n - 1][j] < 1e16)
{
ans = j;
}
cout << ans;
}
Compilation message
segments.cpp:35:50: warning: missing terminating ' character
#include <ext/pb_ds/detail/standard_policies.hpp>'
^
segments.cpp:35:50: warning: extra tokens at end of #include directive
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4344 KB |
Output is correct |
18 |
Correct |
7 ms |
4344 KB |
Output is correct |
19 |
Correct |
15 ms |
4316 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
21 |
Correct |
6 ms |
4344 KB |
Output is correct |
22 |
Correct |
5 ms |
3192 KB |
Output is correct |
23 |
Correct |
4 ms |
2296 KB |
Output is correct |
24 |
Correct |
6 ms |
4336 KB |
Output is correct |
25 |
Correct |
6 ms |
4344 KB |
Output is correct |
26 |
Correct |
6 ms |
4344 KB |
Output is correct |
27 |
Correct |
18 ms |
4344 KB |
Output is correct |
28 |
Correct |
6 ms |
4344 KB |
Output is correct |
29 |
Correct |
6 ms |
4344 KB |
Output is correct |
30 |
Correct |
8 ms |
4476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4344 KB |
Output is correct |
18 |
Correct |
7 ms |
4344 KB |
Output is correct |
19 |
Correct |
15 ms |
4316 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
21 |
Correct |
6 ms |
4344 KB |
Output is correct |
22 |
Correct |
5 ms |
3192 KB |
Output is correct |
23 |
Correct |
4 ms |
2296 KB |
Output is correct |
24 |
Correct |
6 ms |
4336 KB |
Output is correct |
25 |
Correct |
6 ms |
4344 KB |
Output is correct |
26 |
Correct |
6 ms |
4344 KB |
Output is correct |
27 |
Correct |
18 ms |
4344 KB |
Output is correct |
28 |
Correct |
6 ms |
4344 KB |
Output is correct |
29 |
Correct |
6 ms |
4344 KB |
Output is correct |
30 |
Correct |
8 ms |
4476 KB |
Output is correct |
31 |
Correct |
91 ms |
70988 KB |
Output is correct |
32 |
Correct |
111 ms |
70956 KB |
Output is correct |
33 |
Correct |
140 ms |
70840 KB |
Output is correct |
34 |
Execution timed out |
1553 ms |
70948 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4344 KB |
Output is correct |
18 |
Correct |
7 ms |
4344 KB |
Output is correct |
19 |
Correct |
15 ms |
4316 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
21 |
Correct |
6 ms |
4344 KB |
Output is correct |
22 |
Correct |
5 ms |
3192 KB |
Output is correct |
23 |
Correct |
4 ms |
2296 KB |
Output is correct |
24 |
Correct |
6 ms |
4336 KB |
Output is correct |
25 |
Correct |
6 ms |
4344 KB |
Output is correct |
26 |
Correct |
6 ms |
4344 KB |
Output is correct |
27 |
Correct |
18 ms |
4344 KB |
Output is correct |
28 |
Correct |
6 ms |
4344 KB |
Output is correct |
29 |
Correct |
6 ms |
4344 KB |
Output is correct |
30 |
Correct |
8 ms |
4476 KB |
Output is correct |
31 |
Correct |
91 ms |
70988 KB |
Output is correct |
32 |
Correct |
111 ms |
70956 KB |
Output is correct |
33 |
Correct |
140 ms |
70840 KB |
Output is correct |
34 |
Execution timed out |
1553 ms |
70948 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
4344 KB |
Output is correct |
17 |
Correct |
6 ms |
4344 KB |
Output is correct |
18 |
Correct |
7 ms |
4344 KB |
Output is correct |
19 |
Correct |
15 ms |
4316 KB |
Output is correct |
20 |
Correct |
6 ms |
4344 KB |
Output is correct |
21 |
Correct |
6 ms |
4344 KB |
Output is correct |
22 |
Correct |
5 ms |
3192 KB |
Output is correct |
23 |
Correct |
4 ms |
2296 KB |
Output is correct |
24 |
Correct |
6 ms |
4336 KB |
Output is correct |
25 |
Correct |
6 ms |
4344 KB |
Output is correct |
26 |
Correct |
6 ms |
4344 KB |
Output is correct |
27 |
Correct |
18 ms |
4344 KB |
Output is correct |
28 |
Correct |
6 ms |
4344 KB |
Output is correct |
29 |
Correct |
6 ms |
4344 KB |
Output is correct |
30 |
Correct |
8 ms |
4476 KB |
Output is correct |
31 |
Correct |
91 ms |
70988 KB |
Output is correct |
32 |
Correct |
111 ms |
70956 KB |
Output is correct |
33 |
Correct |
140 ms |
70840 KB |
Output is correct |
34 |
Execution timed out |
1553 ms |
70948 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |