| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 166628 | abil | K blocks (IZhO14_blocks) | C++14 | 1087 ms | 4600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
int a[N], dp[1012][1012], table[20][1012], n, l[N];
void build(){
for(int i = 2;i <= n; i++){
l[i] = l[i / 2] + 1;
}
for(int i = 1;i <= n; i++){
table[0][i] = a[i];
}
for(int i = 1;i <= l[n]; i++){
for(int j = 1;j <= n; j++){
table[i][j] = max(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
}
}
}
int get(int left,int right){
int logg = l[right - left + 1];
return max(table[logg][left], table[logg][right - (1 << logg) + 1]);
}
main()
{
int k;
scanf("%d%d", &n, &k);
for(int i = 1;i <= n; i++){
scanf("%d", &a[i]);
}
build();
memset(dp, 0x3f3f3f3f,sizeof(dp));
for(int i = 1;i <= n; i++){
dp[1][i] = get(1, i);
}
for(int i = 2;i <= k; i++){
for(int j = i;j <= n; j++){
for(int p = j;p <= n; p++){
dp[i][p] = min(dp[i][p], dp[i - 1][j - 1] + get(j, p));
}
}
}
cout << dp[k][n];
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
