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>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 4005
int n, d, t;
int ti[MAXN];
int cost[MAXN][MAXN];
ll dp[MAXN][MAXN];
void dnc(int i, int lo, int hi, int optl, int optr) {
if (lo > hi) return;
int j = lo + hi >> 1;
int opt = -1;
dp[i][j] = LINF;
REP (k, optl, min(optr + 1, j)) {
if (dp[i][j] > dp[i - 1][k] + cost[k + 1][j]) {
dp[i][j] = dp[i - 1][k] + cost[k + 1][j];
opt = k;
}
}
dnc(i, lo, j - 1, optl, opt);
dnc(i, j + 1, hi, opt, optr);
}
int main() {
scanf("%d%d%d", &n, &d, &t);
REP (i, 1, n + 1) {
scanf("%d", &ti[i]);
}
REP (i, 1, n + 1) {
ll r = -1;
int cur = 0;
REP (j, i, n + 1) {
if (t >= ti[j]) mxto(r, t - ti[j] + j);
if (r >= j) cur++;
cost[i][j] = cur;
}
}
REP (i, 1, n + 1) {
dp[0][i] = cost[1][i];
}
REP (i, 1, d + 1) {
dnc(i, 1, n, 1, n);
}
printf("%lld\n", dp[d][n]);
return 0;
}
Compilation message (stderr)
prison.cpp: In function 'void dnc(int, int, int, int, int)':
prison.cpp:34:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int j = lo + hi >> 1;
| ~~~^~~~
prison.cpp: In function 'int main()':
prison.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d%d%d", &n, &d, &t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
prison.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d", &ti[i]);
| ~~~~~^~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |