# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
473622 | rainboy | Cover (COCI18_cover) | C11 | 3 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 5000
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N], yy[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : yy[ii[j]] - yy[i_];
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
long long xx_[N], yy_[N];
double cross(int i, int j, int k) {
return (double) (xx_[j] - xx_[i]) * (yy_[k] - yy_[i]) - (double) (xx_[k] - xx_[i]) * (yy_[j] - yy_[i]);
}
long long eval(int i, int x) {
return xx_[i] * x + yy_[i];
}
int main() {
static int ii[N], qu[N];
static long long dp[N + 1];
int n, n_, i, j, head, cnt;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &xx[i], &yy[i]);
if (xx[i] < 0)
xx[i] = -xx[i];
if (yy[i] < 0)
yy[i] = -yy[i];
ii[i] = i;
}
sort(ii, 0, n);
n_ = 0;
for (i = 0; i < n; i++) {
while (n_ > 0 && yy[ii[n_ - 1]] <= yy[ii[i]])
n_--;
ii[n_++] = ii[i];
}
n = n_;
dp[0] = 0;
head = cnt = 0;
for (j = 1; j <= n; j++) {
int x;
xx_[j - 1] = yy[ii[j - 1]], yy_[j - 1] = dp[j - 1];
while (cnt >= 2 && cross(qu[head + cnt - 2], qu[head + cnt - 1], j - 1) >= 0)
cnt--;
qu[head + cnt++] = j - 1;
x = xx[ii[j - 1]];
while (cnt >= 2 && eval(qu[head], x) >= eval(qu[head + 1], x))
head++, cnt--;
dp[j] = eval(qu[head], x);
}
printf("%lld\n", dp[n] * 4);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |