Submission #671282

# Submission time Handle Problem Language Result Execution time Memory
671282 2022-12-12T18:21:56 Z rainboy Hamburg Steak (JOI20_hamburg) C
15 / 100
246 ms 14336 KB
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#define N	200000
#define K	4
#define INF	0x3f3f3f3f3f3f3f3fLL

long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }

long long xxl[N], xxr[N], yyl[N], yyr[N], xx[K], yy[K]; int n;

int pierced(int i, int k) {
	int h;

	for (h = 0; h < k; h++)
		if (xxl[i] <= xx[h] && xx[h] <= xxr[i] && yyl[i] <= yy[h] && yy[h] <= yyr[i])
			return 1;
	return 0;
}

void solve(int h_, int k) {
	int h, i;
	long long xl, xr, yl, yr;

	xl = INF, xr = -1, yl = INF, yr = -1;
	for (i = 0; i < n; i++)
		if (!pierced(i, h_))
			xl = min(xl, xxr[i]), xr = max(xr, xxl[i]), yl = min(yl, yyr[i]), yr = max(yr, yyl[i]);
	if (xl == INF) {
		for (h = h_; h < k; h++)
			xx[h] = 1, yy[h] = 1;
		for (h = 0; h < k; h++)
			printf("%lld %lld\n", xx[h], yy[h]);
		exit(0);
	} else if (h_ < k) {
		xx[h_] = xl, yy[h_] = yl, solve(h_ + 1, k);
		xx[h_] = xl, yy[h_] = yr, solve(h_ + 1, k);
		xx[h_] = xr, yy[h_] = yl, solve(h_ + 1, k);
		xx[h_] = xr, yy[h_] = yr, solve(h_ + 1, k);
	}
}

long long ll[N], rr[N]; int ii0[N], ii1[N], ii2[N], n0, n1, n2; long long xl, xr, yl, yr;

long long idx(long long x, long long y) {
	if (y == yl)
		return x - xl;
	if (x == xr)
		return xr - xl + y - yl;
	if (y == yr)
		return xr - xl + yr - yl + xr - x;
	if (x == xl)
		return xr - xl + yr - yl + xr - xl + yr - y;
	return -1;
}

long long xl_, yl_, xr_, yr_;

void get_min_max() {
	int h, i, i_, pierced;

	xl_ = INF, xr_ = -1, yl_ = INF, yr_ = -1;
	for (i = 0; i < n0; i++) {
		i_ = ii0[i], pierced = 0;
		for (h = 0; h < 4; h++) {
			long long z = idx(xx[h], yy[h]);

			if (ll[i_] <= z && z <= rr[i_]) {
				pierced = 1;
				break;
			}
		}
		if (!pierced)
			xl_ = min(xl_, xxr[i]), xr_ = max(xr_, xxl[i]), yl_ = min(yl_, yyr[i]), yr_ = max(yr_, yyl[i]);
	}
	for (i = 0; i < n1; i++) {
		i_ = ii1[i], pierced = 0;
		for (h = 0; h < 4; h++)
			if (ll[i_] <= xx[h] && xx[h] <= rr[i_]) {
				pierced = 1;
				break;
			}
		if (!pierced)
			xl_ = min(xl_, xxr[i]), xr_ = max(xr_, xxl[i]), yl_ = min(yl_, yyr[i]), yr_ = max(yr_, yyl[i]);
	}
	for (i = 0; i < n2; i++) {
		i_ = ii2[i], pierced = 0;
		for (h = 0; h < 4; h++)
			if (ll[i_] <= yy[h] && yy[h] <= rr[i_]) {
				pierced = 1;
				break;
			}
		if (!pierced)
			xl_ = min(xl_, xxr[i]), xr_ = max(xr_, xxl[i]), yl_ = min(yl_, yyr[i]), yr_ = max(yr_, yyl[i]);
	}
}

void solve_(int h_, int k) {
	int h;

	get_min_max();
	if (xl_ == INF) {
		for (h = h_; h < k; h++)
			xx[h] = 1, yy[h] = 1;
		for (h = 0; h < k; h++)
			printf("%lld %lld\n", xx[h], yy[h]);
		exit(0);
	} else {
		xx[h_] = xl, yy[h_] = yl;
		if (idx(xx[h_], yy[h_]) != -1)
			solve(h_ + 1, k);
		xx[h_] = xl, yy[h_] = yr;
		if (idx(xx[h_], yy[h_]) != -1)
			solve(h_ + 1, k);
		xx[h_] = xr, yy[h_] = yl;
		if (idx(xx[h_], yy[h_]) != -1)
			solve(h_ + 1, k);
		xx[h_] = xr, yy[h_] = yr;
		if (idx(xx[h_], yy[h_]) != -1)
			solve(h_ + 1, k);
	}
}

int main() {
	int k, i;
	long long l, r;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%lld%lld%lld%lld", &xxl[i], &yyl[i], &xxr[i], &yyr[i]);
	solve(0, k);
	xl = INF, xr = -1, yl = INF, yr = -1;
	for (i = 0; i < n; i++)
		xl = min(xl, xxr[i]), xr = max(xr, xxl[i]), yl = min(yl, yyr[i]), yr = max(yr, yyl[i]);
	assert(k == 4 && xl < xr && yl < yr);
	for (i = 0; i < n; i++)
		xxl[i] = max(xxl[i], xl), xxr[i] = min(xxr[i], xr), yyl[i] = max(yyl[i], yl), yyr[i] = min(yyr[i], yr);
	for (i = 0; i < n; i++)
		if (xl < xxl[i] && xxr[i] < xr && yyl[i] == yl && yyr[i] == yr)
			ll[i] = xxl[i], rr[i] = xxr[i], ii1[n1++] = i;
		else if (yl < yyl[i] && yyr[i] < yr && xxl[i] == xl && xxr[i] == xr)
			ll[i] = yyl[i], rr[i] = yyr[i], ii2[n2++] = i;
		else {
			l = INF, r = -1;
			if (yyl[i] == yl) {
				l = min(l, xxl[i] - xl), r = max(r, xxr[i] - xl);
				if (xxl[i] == xl)
					l += xr - xl + yr - yl + xr - xl + yr - yl, r += xr - xl + yr - yl + xr - xl + yr - yl;
			}
			if (xxr[i] == xr)
				l = min(l, xr - xl + yyl[i] - yl), r = max(r, xr - xl + yyr[i] - yl);
			if (yyr[i] == yr)
				l = min(l, xr - xl + yr - yl + xr - xxr[i]), r = max(r, xr - xl + yr - yl + xr - xxl[i]);
			if (xxl[i] == xl)
				l = min(l, xr - xl + yr - yl + xr - xl + yr - yyr[i]), r = max(r, xr - xl + yr - yl + xr - xl + yr - yyl[i]);
			ll[i] = l, rr[i] = r, ii0[n0++] = i;
		}
	solve_(0, 4);
	return 0;
}

Compilation message

hamburg.c: In function 'main':
hamburg.c:130:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
hamburg.c:132:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |   scanf("%lld%lld%lld%lld", &xxl[i], &yyl[i], &xxr[i], &yyr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 432 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 428 KB Output is correct
10 Correct 2 ms 432 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 404 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 432 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 10 ms 340 KB Output is correct
14 Incorrect 17 ms 412 KB Unexpected end of file - int32 expected
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 79 ms 14332 KB Output is correct
6 Correct 82 ms 14260 KB Output is correct
7 Correct 79 ms 14196 KB Output is correct
8 Correct 88 ms 14260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 82 ms 14156 KB Output is correct
6 Correct 88 ms 14296 KB Output is correct
7 Correct 83 ms 14224 KB Output is correct
8 Correct 91 ms 14156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 432 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 428 KB Output is correct
10 Correct 2 ms 432 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 85 ms 14180 KB Output is correct
14 Correct 89 ms 14160 KB Output is correct
15 Correct 81 ms 14120 KB Output is correct
16 Correct 82 ms 14284 KB Output is correct
17 Correct 82 ms 14256 KB Output is correct
18 Correct 84 ms 14204 KB Output is correct
19 Correct 85 ms 14336 KB Output is correct
20 Correct 99 ms 14160 KB Output is correct
21 Correct 246 ms 14228 KB Output is correct
22 Correct 166 ms 14280 KB Output is correct
23 Correct 137 ms 14248 KB Output is correct
24 Correct 145 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 404 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 432 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 10 ms 340 KB Output is correct
14 Incorrect 17 ms 412 KB Unexpected end of file - int32 expected
15 Halted 0 ms 0 KB -