#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
#define pii pair<int,int>
#define pb push_back
#define bit(mask,i) ((mask >> i) & 1)
#define mask(i) (1 << (i))
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define turn_on(mask,i) ((mask | (1 << i))
#define turn_off(mask,i) (mask ^ (1 << i))
#define count_1(x) __builtin_popcount(x)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int Base = 37;
const int MOD = 1e9 + 7;
const int nmax = 1e5;
const int size = 320;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int n, k;
int a[nmax + 10], b[nmax + 10][20];
int dp[nmax + 10][105];
void input()
{
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
}
void RMQ()
{
for (int i = 1; i <= n; i++) b[i][0] = a[i];
for (int j = 1; (1 << j) <= n; j++)
{
for (int i = 0; i + (1 << j) - 1 <= n; i++)
{
b[i][j] = max(b[i][j - 1] , b[i + (1 << (j - 1))][j - 1]);
}
}
}
int get(int l , int r)
{
int k = __lg(r - l + 1);
return max(b[l][k] , b[r - (1 << k) + 1][k]);
}
void process()
{
memset(dp , 0x3f , sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= k; i++)
{
for (int j = i; j <= n; j++)
{
for (int h = i; h <= j; h++)
{
dp[i][j] = min(dp[i][j] , dp[i - 1][h - 1] + get(h , j));
}
}
}
cout << dp[k][n];
}
signed main()
{
faster
// freopen ("TASK.INP", "r", stdin);
// freopen ("TASK.OUT", "w", stdout);
input();
RMQ();
process();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
82512 KB |
Output is correct |
2 |
Correct |
13 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82684 KB |
Output is correct |
4 |
Correct |
12 ms |
82512 KB |
Output is correct |
5 |
Correct |
11 ms |
82652 KB |
Output is correct |
6 |
Correct |
12 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82528 KB |
Output is correct |
8 |
Correct |
12 ms |
82512 KB |
Output is correct |
9 |
Correct |
11 ms |
82648 KB |
Output is correct |
10 |
Correct |
11 ms |
82512 KB |
Output is correct |
11 |
Correct |
12 ms |
82512 KB |
Output is correct |
12 |
Correct |
11 ms |
82632 KB |
Output is correct |
13 |
Correct |
11 ms |
82680 KB |
Output is correct |
14 |
Correct |
12 ms |
82512 KB |
Output is correct |
15 |
Correct |
11 ms |
82512 KB |
Output is correct |
16 |
Correct |
12 ms |
82680 KB |
Output is correct |
17 |
Correct |
11 ms |
82512 KB |
Output is correct |
18 |
Correct |
11 ms |
82600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
82512 KB |
Output is correct |
2 |
Correct |
10 ms |
82656 KB |
Output is correct |
3 |
Correct |
10 ms |
82512 KB |
Output is correct |
4 |
Correct |
10 ms |
82512 KB |
Output is correct |
5 |
Correct |
10 ms |
82612 KB |
Output is correct |
6 |
Correct |
11 ms |
82512 KB |
Output is correct |
7 |
Correct |
10 ms |
82512 KB |
Output is correct |
8 |
Correct |
10 ms |
82512 KB |
Output is correct |
9 |
Correct |
10 ms |
82512 KB |
Output is correct |
10 |
Correct |
10 ms |
82512 KB |
Output is correct |
11 |
Correct |
10 ms |
82680 KB |
Output is correct |
12 |
Correct |
10 ms |
82512 KB |
Output is correct |
13 |
Correct |
10 ms |
82644 KB |
Output is correct |
14 |
Correct |
10 ms |
82620 KB |
Output is correct |
15 |
Correct |
10 ms |
82512 KB |
Output is correct |
16 |
Correct |
10 ms |
82512 KB |
Output is correct |
17 |
Correct |
10 ms |
82512 KB |
Output is correct |
18 |
Correct |
10 ms |
82512 KB |
Output is correct |
19 |
Correct |
10 ms |
82512 KB |
Output is correct |
20 |
Correct |
10 ms |
82596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
82512 KB |
Output is correct |
2 |
Correct |
13 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82684 KB |
Output is correct |
4 |
Correct |
12 ms |
82512 KB |
Output is correct |
5 |
Correct |
11 ms |
82652 KB |
Output is correct |
6 |
Correct |
12 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82528 KB |
Output is correct |
8 |
Correct |
12 ms |
82512 KB |
Output is correct |
9 |
Correct |
11 ms |
82648 KB |
Output is correct |
10 |
Correct |
11 ms |
82512 KB |
Output is correct |
11 |
Correct |
12 ms |
82512 KB |
Output is correct |
12 |
Correct |
11 ms |
82632 KB |
Output is correct |
13 |
Correct |
11 ms |
82680 KB |
Output is correct |
14 |
Correct |
12 ms |
82512 KB |
Output is correct |
15 |
Correct |
11 ms |
82512 KB |
Output is correct |
16 |
Correct |
12 ms |
82680 KB |
Output is correct |
17 |
Correct |
11 ms |
82512 KB |
Output is correct |
18 |
Correct |
11 ms |
82600 KB |
Output is correct |
19 |
Correct |
12 ms |
82512 KB |
Output is correct |
20 |
Correct |
10 ms |
82656 KB |
Output is correct |
21 |
Correct |
10 ms |
82512 KB |
Output is correct |
22 |
Correct |
10 ms |
82512 KB |
Output is correct |
23 |
Correct |
10 ms |
82612 KB |
Output is correct |
24 |
Correct |
11 ms |
82512 KB |
Output is correct |
25 |
Correct |
10 ms |
82512 KB |
Output is correct |
26 |
Correct |
10 ms |
82512 KB |
Output is correct |
27 |
Correct |
10 ms |
82512 KB |
Output is correct |
28 |
Correct |
10 ms |
82512 KB |
Output is correct |
29 |
Correct |
10 ms |
82680 KB |
Output is correct |
30 |
Correct |
10 ms |
82512 KB |
Output is correct |
31 |
Correct |
10 ms |
82644 KB |
Output is correct |
32 |
Correct |
10 ms |
82620 KB |
Output is correct |
33 |
Correct |
10 ms |
82512 KB |
Output is correct |
34 |
Correct |
10 ms |
82512 KB |
Output is correct |
35 |
Correct |
10 ms |
82512 KB |
Output is correct |
36 |
Correct |
10 ms |
82512 KB |
Output is correct |
37 |
Correct |
10 ms |
82512 KB |
Output is correct |
38 |
Correct |
10 ms |
82596 KB |
Output is correct |
39 |
Correct |
11 ms |
82512 KB |
Output is correct |
40 |
Correct |
10 ms |
82684 KB |
Output is correct |
41 |
Correct |
10 ms |
82512 KB |
Output is correct |
42 |
Correct |
10 ms |
82512 KB |
Output is correct |
43 |
Correct |
10 ms |
82512 KB |
Output is correct |
44 |
Correct |
10 ms |
82512 KB |
Output is correct |
45 |
Correct |
10 ms |
82512 KB |
Output is correct |
46 |
Correct |
10 ms |
82512 KB |
Output is correct |
47 |
Correct |
10 ms |
82512 KB |
Output is correct |
48 |
Correct |
11 ms |
82512 KB |
Output is correct |
49 |
Correct |
11 ms |
82512 KB |
Output is correct |
50 |
Correct |
13 ms |
82680 KB |
Output is correct |
51 |
Correct |
12 ms |
82660 KB |
Output is correct |
52 |
Correct |
12 ms |
82512 KB |
Output is correct |
53 |
Correct |
12 ms |
82708 KB |
Output is correct |
54 |
Correct |
11 ms |
82512 KB |
Output is correct |
55 |
Correct |
12 ms |
82512 KB |
Output is correct |
56 |
Correct |
12 ms |
82512 KB |
Output is correct |
57 |
Correct |
13 ms |
82512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
82512 KB |
Output is correct |
2 |
Correct |
13 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82684 KB |
Output is correct |
4 |
Correct |
12 ms |
82512 KB |
Output is correct |
5 |
Correct |
11 ms |
82652 KB |
Output is correct |
6 |
Correct |
12 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82528 KB |
Output is correct |
8 |
Correct |
12 ms |
82512 KB |
Output is correct |
9 |
Correct |
11 ms |
82648 KB |
Output is correct |
10 |
Correct |
11 ms |
82512 KB |
Output is correct |
11 |
Correct |
12 ms |
82512 KB |
Output is correct |
12 |
Correct |
11 ms |
82632 KB |
Output is correct |
13 |
Correct |
11 ms |
82680 KB |
Output is correct |
14 |
Correct |
12 ms |
82512 KB |
Output is correct |
15 |
Correct |
11 ms |
82512 KB |
Output is correct |
16 |
Correct |
12 ms |
82680 KB |
Output is correct |
17 |
Correct |
11 ms |
82512 KB |
Output is correct |
18 |
Correct |
11 ms |
82600 KB |
Output is correct |
19 |
Correct |
12 ms |
82512 KB |
Output is correct |
20 |
Correct |
10 ms |
82656 KB |
Output is correct |
21 |
Correct |
10 ms |
82512 KB |
Output is correct |
22 |
Correct |
10 ms |
82512 KB |
Output is correct |
23 |
Correct |
10 ms |
82612 KB |
Output is correct |
24 |
Correct |
11 ms |
82512 KB |
Output is correct |
25 |
Correct |
10 ms |
82512 KB |
Output is correct |
26 |
Correct |
10 ms |
82512 KB |
Output is correct |
27 |
Correct |
10 ms |
82512 KB |
Output is correct |
28 |
Correct |
10 ms |
82512 KB |
Output is correct |
29 |
Correct |
10 ms |
82680 KB |
Output is correct |
30 |
Correct |
10 ms |
82512 KB |
Output is correct |
31 |
Correct |
10 ms |
82644 KB |
Output is correct |
32 |
Correct |
10 ms |
82620 KB |
Output is correct |
33 |
Correct |
10 ms |
82512 KB |
Output is correct |
34 |
Correct |
10 ms |
82512 KB |
Output is correct |
35 |
Correct |
10 ms |
82512 KB |
Output is correct |
36 |
Correct |
10 ms |
82512 KB |
Output is correct |
37 |
Correct |
10 ms |
82512 KB |
Output is correct |
38 |
Correct |
10 ms |
82596 KB |
Output is correct |
39 |
Correct |
11 ms |
82512 KB |
Output is correct |
40 |
Correct |
10 ms |
82684 KB |
Output is correct |
41 |
Correct |
10 ms |
82512 KB |
Output is correct |
42 |
Correct |
10 ms |
82512 KB |
Output is correct |
43 |
Correct |
10 ms |
82512 KB |
Output is correct |
44 |
Correct |
10 ms |
82512 KB |
Output is correct |
45 |
Correct |
10 ms |
82512 KB |
Output is correct |
46 |
Correct |
10 ms |
82512 KB |
Output is correct |
47 |
Correct |
10 ms |
82512 KB |
Output is correct |
48 |
Correct |
11 ms |
82512 KB |
Output is correct |
49 |
Correct |
11 ms |
82512 KB |
Output is correct |
50 |
Correct |
13 ms |
82680 KB |
Output is correct |
51 |
Correct |
12 ms |
82660 KB |
Output is correct |
52 |
Correct |
12 ms |
82512 KB |
Output is correct |
53 |
Correct |
12 ms |
82708 KB |
Output is correct |
54 |
Correct |
11 ms |
82512 KB |
Output is correct |
55 |
Correct |
12 ms |
82512 KB |
Output is correct |
56 |
Correct |
12 ms |
82512 KB |
Output is correct |
57 |
Correct |
13 ms |
82512 KB |
Output is correct |
58 |
Execution timed out |
1080 ms |
84816 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |