#include <stdio.h>
#define N1 200000
#define N2 50000
#define LG 16 /* LG = ceil(log2(N2)) */
#define N_ (1 + N2 * (LG + 1))
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int abs_(int a) { return a > 0 ? a : -a; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N1], yy[N1], xx_[N2], yy_[N2], n;
int t, u, v;
int check(int d) {
if (t == 1) {
int i, xmn, xmx, ymn, ymx;
xmn = INF, xmx = -INF, ymn = INF, ymx = -INF;
for (i = 0; i < n; i++) {
xmn = min(xmn, xx[i]), xmx = max(xmx, xx[i]);
ymn = min(ymn, yy[i]), ymx = max(ymx, yy[i]);
}
u = -1;
for (i = 0; i < n; i++)
if (xx[i] - xmn <= d && xmx - xx[i] <= d && yy[i] - ymn <= d && ymx - yy[i] <= d) {
u = i;
return 1;
}
return 0;
} else {
int i;
for (u = 0; u < n; u++) {
int xmn = INF, xmx = -INF, ymn = INF, ymx = -INF;
for (i = 0; i < n; i++) {
if (max(abs_(xx[i] - xx[u]), abs_(yy[i] - yy[u])) <= d)
continue;
xmn = min(xmn, xx[i]), xmx = max(xmx, xx[i]);
ymn = min(ymn, yy[i]), ymx = max(ymx, yy[i]);
}
v = -1;
for (i = 0; i < n; i++)
if (xx[i] - xmn <= d && xmx - xx[i] <= d && yy[i] - ymn <= d && ymx - yy[i] <= d) {
v = i;
return 1;
}
}
return 0;
}
}
int *zz;
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)
if (zz[ii[j]] == zz[i_])
j++;
else if (zz[ii[j]] < zz[i_]) {
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;
}
}
int main() {
static int ii[N2], jj[N2];
int i, j, lower, upper;
scanf("%d%d", &t, &n);
for (i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
xx[i] = x + y, yy[i] = x - y;
}
for (i = 0; i < n; i++)
ii[i] = i;
zz = xx, sort(ii, 0, n);
for (i = 0; i < n; i++)
xx_[ii[i]] = i;
for (j = 0; j < n; j++)
jj[j] = j;
zz = yy, sort(jj, 0, n);
for (j = 0; j < n; j++)
yy_[jj[j]] = j;
lower = -1, upper = INF;
while (upper - lower > 1) {
int d = (lower + upper) / 2;
if (check(d))
upper = d;
else
lower = d;
}
check(upper);
printf("%d\n", upper);
if (t == 1)
printf("%d\n", u + 1);
else
printf("%d %d\n", u + 1, v + 1);
return 0;
}
Compilation message
kosta.c: In function 'main':
kosta.c:87:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d%d", &t, &n);
| ^~~~~~~~~~~~~~~~~~~~~
kosta.c:91:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | scanf("%d%d", &x, &y);
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
26 ms |
2616 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
3796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1081 ms |
348 KB |
Output is correct |
2 |
Correct |
980 ms |
392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
348 KB |
Output is correct |
2 |
Correct |
757 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5056 ms |
1200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
1228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |