이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* I do it for the glory */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<double, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
#define lc id << 1
#define rc lc | 1
const int N = 1e6 + 10, MOD = 1e9 + 7; const double eps = 1e-14;
int R[N], t[N], n, T, D; pii dp[N], seg[N << 2];
void bld(int id = 1, int l = 1, int r = n + 1) {
seg[id] = {MOD, 0};
if (r - l < 2) return;
int md = (l + r) >> 1;
bld(lc, l, md), bld(rc, md, r);
}
void upd(int p, double x, int y, int id = 1, int l = 1, int r = n + 1) {
if (r - l < 2) { seg[id] = min(seg[id], {x, y}); return; }
int md = (l + r) >> 1;
p < md ? upd(p, x, y, lc, l, md) : upd(p, x, y, rc, md, r);
seg[id] = min(seg[lc], seg[rc]);
}
pii get(int ql, int qr, int id = 1, int l = 1, int r = n + 1) {
if (qr <= l || r <= ql) return {MOD, 0};
if (ql <= l && r <= qr) { return seg[id]; }
int md = (l + r) >> 1;
return min(get(ql, qr, lc, l, md), get(ql, qr, rc, md, r));
}
pii get(double l) {
bld(); fill(dp, dp + n + 2, pii(0.0, 0));
if (t[n] <= T) dp[n] = {1.0, 0};
else dp[n] = {0.0, 0};
upd(n, dp[n].F + n, dp[n].S);
for (int i = n - 1; i; i--) {
if (R[i] < i)
if (l <= 0) dp[i] = {dp[i + 1].F + l, dp[i + 1].S + 1};
else dp[i] = dp[i + 1];
else {
pii x = get(i + 1, R[i] + 2);
dp[i] = {x.F + l - i, x.S + 1};
dp[i] = min(dp[i], {dp[R[i] + 1].F + R[i] - i + 1, dp[R[i] + 1].S});
}
upd(i, dp[i].F + i, dp[i].S);
}
return dp[1];
}
int main() {
scanf("%d%d%d", &n, &D, &T);
for (int i = 1; i <= n; i++)
scanf("%d", &t[i]);
for (int i = n; i; i--) {
for (R[i] = i + 1; R[i] <= n && t[R[i]] - R[i] > t[i] - i; R[i] = R[R[i]]);
}
for (int i = n; i; i--) {
if (R[i] <= min(n, i + T - t[i]))
R[i] = R[R[i]];
else R[i] = min(n, i + T - t[i]);
if (R[i] < i) R[i] = -1;
}
double l = -N, r = N;
for (; r - l > 1; ) {
double md = (l + r) / 2.0;
if (get(md).S >= D) l = md;
else r = md;
}
pii A = get(l);
if (A.S == D) {
int ret = A.F - l * D;
printf("%d\n", ret);
} else {
int x = A.F - l * A.S;
pii B = get(r); int y = B.F - r * B.S;
printf("%d\n", y + (D - B.S) * (x - y) / (A.S - B.S));
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'int main()':
prison.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d%d%d", &n, &D, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
prison.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d", &t[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... |