| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1349600 | haru09 | Holding (COCI20_holding) | C++20 | 51 ms | 8656 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define task "code"
const int ar = 1e2 + 5;
const ll mod = 1e9 + 7;
const int N = 1e4;
const int inf = 1e9;
int q, n = 0, m = 0, l, r, k;
pair<int, int> a[ar], b[ar];
int dp[ar][N + 5], f[ar][N + 5];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> q >> l >> r >> k;
for (int i = 1; i <= q; i++)
{
int x;
cin >> x;
if (l <= i && i <= r) a[++n] = {x, i};
else b[++m] = {x, i};
}
memset(dp, 0x3f, sizeof dp);
memset(f, 0x3f, sizeof f);
for (int i = 0; i <= m; i++) f[i][0] = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= m; j++)
{
for (int t = 0; t <= k; t++)
{
dp[j][t] = min(dp[j][t], f[j][t] + a[i].fi);
if (j >= 1) dp[j][t] = min(dp[j][t], dp[j - 1][t]);
if (abs(a[i].se - b[j].se) <= t && j >= 1)
{
dp[j][t] = min(dp[j][t], f[j - 1][t - abs(a[i].se - b[j].se)] + b[j].fi);
}
}
}
for (int j = 0; j <= m; j++)
{
for (int t = 0; t <= k; t++)
{
//cout << i << ' ' << j << ' ' << t << ' ' << dp[j][t] << '\n';
f[j][t] = dp[j][t];
dp[j][t] = inf;
}
}
}
int ans = inf;
for (int i = 0; i <= k; i++) ans = min(ans, f[m][i]);
cout << ans;
}
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... | ||||
