| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 764651 | ind1v | 구경하기 (JOI13_watching) | C++11 | 111 ms | 8236 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, p, q;
long long a[N];
int dp[N][N / 2];
int xx[N], yy[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> p >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (p + q >= n) {
cout << 1;
exit(0);
}
sort(a + 1, a + n + 1);
a[0] = numeric_limits<long long>::min();
if (q <= p) {
int l = 1, r = 1000000000, ans = -1;
while (l <= r) {
int m = l + r >> 1;
for (int i = 1, j = 0; i <= n; i++) {
while (j + 1 < i && a[j + 1] <= a[i] - m) {
++j;
}
xx[i] = j;
}
for (int i = 1, j = 0; i <= n; i++) {
while (j + 1 < i && a[j + 1] <= a[i] - 2 * m) {
++j;
}
yy[i] = j;
}
memset(dp, 0x3f, sizeof(dp));
for (int j = 0; j <= q; j++) {
dp[0][j] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= q; j++) {
dp[i][j] = min(dp[i][j], 1 + dp[xx[i]][j]);
if (j > 0) {
dp[i][j] = min(dp[i][j], dp[yy[i]][j - 1]);
}
}
}
if (dp[n][q] <= p) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
cout << ans;
} else {
int l = 1, r = 1000000000, ans = -1;
while (l <= r) {
int m = l + r >> 1;
for (int i = 1, j = 0; i <= n; i++) {
while (j + 1 < i && a[j + 1] <= a[i] - m) {
++j;
}
xx[i] = j;
}
for (int i = 1, j = 0; i <= n; i++) {
while (j + 1 < i && a[j + 1] <= a[i] - 2 * m) {
++j;
}
yy[i] = j;
}
memset(dp, 0x3f, sizeof(dp));
for (int j = 0; j <= p; j++) {
dp[0][j] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p; j++) {
dp[i][j] = min(dp[i][j], 1 + dp[yy[i]][j]);
if (j > 0) {
dp[i][j] = min(dp[i][j], dp[xx[i]][j - 1]);
}
}
}
if (dp[n][p] <= q) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
cout << ans;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
