# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91325 | YottaByte | K blocks (IZhO14_blocks) | C++14 | 1037 ms | 8724 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 <stdio.h>
#include <iomanip>
#include <vector>
using namespace std;
const int N = 102;
#define pb push_back
#define ll long long
#define int long long
#define fr first
#define sc second
#define mk make_pair
int b[N][N][N];
int n, a[N], k, t[N * 4], ans = 1e8;
vector < pair < int, int > > lr[N];
void bld(int v = 1, int l = 1, int r = n)
{
if(l == r)
{
t[v] = a[l];
return;
}
else
{
int mid = l + r >> 1ll;
bld(v + v, l, mid);
bld(v + v + 1, mid + 1, r);
}
t[v] = max(t[v + v], t[v + v + 1]);
}
int getmx(int ql, int qr, int v = 1, int l = 1, int r = n)
{
if(l > qr || ql > r) return 0;
if(ql <= l && r <= qr)
return t[v];
int mid = l + r >> 1ll;
return max(getmx(ql, qr, v + v, l, mid), getmx(ql, qr, v + v + 1, mid + 1, r));
}
main()
{
scanf("%lld %lld", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
bld();
for(int i = 1; i <= k; i++)
{
for(int l = 1; l <= n; l++)
{
for(int r = 1; r <= n; r++)
{
b[i][l][r] = 1e9;
}
}
}
for(int l = 1; l <= n - k + 1; l++)
{
for(int r = l; r <= n; r++)
{
b[1][l][r] = getmx(l, r);
}
}
for(int i = 2; i <= k; i++)
{
for(int l = i; l <= n; l++)
{
for(int r = l; r <= n; r++)
{
for(int j = 1; j < l; j++)
{
b[i][l][r] = min(b[i - 1][j][l - 1], b[i][l][r]);
}
b[i][l][r] += getmx(l, r);
}
}
}
for(int l = k; l <= n; l++)
{
ans = min(ans, b[k][l][n]);
}
printf("%lld\n", ans);
}
/**
5 3
1 2 3 4 5
100 50
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
**/
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... |