답안 #216742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216742 2020-03-28T00:53:09 Z ainta 함박 스테이크 (JOI20_hamburg) C++17
15 / 100
628 ms 7480 KB
#include<cstdio>
#include<algorithm>
#define N_ 401000
using namespace std;
int n, K, C[N_], X[N_], Y[N_];
struct Rect {
	int bx, by, ex, ey;
}w[N_];
struct point {
	int x, y;
}U[5];
bool Inside(Rect a, point b) {
	return a.bx <= b.x&&b.x <= a.ex&&a.by <= b.y&&b.y <= a.ey;
}
void Print(point a) {
	printf("%d %d\n", X[a.x], Y[a.y]);
}
void Do(int pv) {
	int i;
	if (pv) {
		for (i = 1; i <= n; i++)if (Inside(w[i], U[pv - 1]))C[i]++;
	}
	if (pv == K) {
		for (i = 1; i <= n; i++) if (!C[i])break;
		if (i > n) {
			for (i = 0; i < K; i++)Print(U[i]);
			exit(0);
		}
		for (i = 1; i <= n; i++)if (Inside(w[i], U[pv - 1]))C[i]--;
		return;
	}
	int Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
	for (i = 1; i <= n; i++) {
		if (C[i])continue;
		Ax = max(Ax, w[i].bx);
		Ay = max(Ay, w[i].by);
		Bx = min(Bx, w[i].ex);
		By = min(By, w[i].ey);
	}
	int yy1 = 0, yy2 = 1e9, yy3 = 0, yy4 = 1e9;
	for (i = 1; i <= n; i++) {
		if (C[i])continue;
		if (w[i].bx <= Bx) {
			yy1 = max(yy1, w[i].by);
			yy2 = min(yy2, w[i].ey);
		}
		if (w[i].ex >= Ax) {
			yy3 = max(yy3, w[i].by);
			yy4 = min(yy4, w[i].ey);
		}
	}
	U[pv] = { Bx, yy1 };
	Do(pv + 1);
	U[pv] = { Bx, yy2 };
	Do(pv + 1);
	U[pv] = { Ax, yy3 };
	Do(pv + 1);
	U[pv] = { Ax, yy4 };
	Do(pv + 1);
	if (pv) {
		for (i = 1; i <= n; i++)if (Inside(w[i], U[pv - 1]))C[i]--;
	}
}
void ReNum(int &a, int *b, int c) {
	a = lower_bound(b + 1, b + c + 1, a) - b;
}

int Next[4][N_], CX = 0, CY = 0, BBx, EEx, BBy, EEy, T[4];

void Go(int pv, int a) {
	T[pv] = a;
	int t = Next[pv][a] - n*2;
	if (t <= 0)return;
	if (pv == 3) {
		if (t < T[0]) return;
		if ((BBy <= T[0] && T[0] <= EEy) || (BBy <= 2 * n + 1 - T[2] && 2 * n + 1 - T[2] <= EEy)) {
			if ((BBx <= T[1] && T[1] <= EEx) || (BBx <= 2 * n + 1 - T[3] && 2 * n + 1 - T[3] <= EEx)) {
				U[0].y = T[0];
				U[1].x = T[1];
				U[2].y = 2 * n + 1 - T[2];
				U[3].x = 2 * n + 1 - T[3];
				for (int i = 0; i < K; i++)Print(U[i]);
				exit(0);
			}
		}

		return;
	}
	Go(pv + 1, t);
	if (pv == 0) {
		if (t > EEx) {
			Go(pv + 1, EEx);
		}
	}
	if (pv == 1) {
		if (t > 2*n-BBy+1) {
			Go(pv + 1, BBy);
		}
	}
	if (pv == 2) {
		if (t > 2 * n - BBx + 1) {
			Go(pv + 1, BBx);
		}
	}
}

int main() {
	int i, j;
	scanf("%d%d", &n, &K);
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d%d", &w[i].bx, &w[i].by, &w[i].ex, &w[i].ey);
		X[++CX] = w[i].bx, X[++CX] = w[i].ex;
		Y[++CY] = w[i].by, Y[++CY] = w[i].ey;
	}
	sort(X + 1, X + CX + 1);
	sort(Y + 1, Y + CY + 1);
	for (i = 1; i <= n; i++) {
		ReNum(w[i].bx, X, CX);
		ReNum(w[i].ex, X, CX);
		ReNum(w[i].by, Y, CY);
		ReNum(w[i].ey, Y, CY);
	}
	Do(0);
	int Ax = 0, Bx = 1e9, Ay = 0, By = 1e9;
	for (i = 1; i <= n; i++) {
		Ax = max(Ax, w[i].bx);
		Ay = max(Ay, w[i].by);
		Bx = min(Bx, w[i].ex);
		By = min(By, w[i].ey);
	}
	if (Ax <= Bx || Ay <= By) {
		while (1) {}
	}
	U[0].x = Bx, U[1].y = Ay, U[2].x = Ax, U[3].y = By;
	BBx = 1, EEx = CX;
	BBy = 1, EEy = CY;
	for (i = 0; i < 4; i++)for (j = 1; j <= n + n; j++)Next[i][j] = 4 * n;
	for (i = 1; i <= n; i++) {
		int ck = 0, c = 0;
		if (w[i].bx <= Bx)ck |= 1, c++;
		if (w[i].ey >= Ay)ck |= 2, c++;
		if (w[i].ex >= Ax)ck |= 4, c++;
		if (w[i].by <= By)ck |= 8, c++;
		if (c >= 3)continue;
		if (ck == 0) {
			while (1) {}
		}
		if (ck == 1) {
			Next[0][w[i].by - 1] = min(Next[0][w[i].by - 1], w[i].ey);
		}
		if (ck == 2) {
			Next[1][w[i].bx - 1] = min(Next[1][w[i].ex - 1], w[i].ex);
		}
		if (ck == 4) {
			Next[2][CY - w[i].ey] = min(Next[2][CY - w[i].ey], CY - w[i].by + 1);
		}
		if (ck == 8) {
			Next[3][CX - w[i].ex] = min(Next[3][CX - w[i].ex], CX - w[i].bx + 1);
		}
		if (ck == 3) {
			Next[0][w[i].by - 1] = min(Next[0][w[i].by - 1], CY + w[i].ex);
		}
		if (ck == 6) {
			Next[1][w[i].bx - 1] = min(Next[1][w[i].bx - 1], CX + CY - w[i].by + 1);
		}
		if (ck == 12) {
			Next[2][CY - w[i].ey] = min(Next[2][CY - w[i].ey], CY + CX - w[i].bx + 1);
		}
		if (ck == 9) {
			Next[3][CX - w[i].ex] = min(Next[3][CX - w[i].ex], CX + w[i].ey);
		}
		if (ck == 5) {
			BBy = max(BBy, w[i].by);
			EEy = min(EEy, w[i].ey);
		}
		if (ck == 10) {
			BBx = max(BBx, w[i].bx);
			EEx = min(EEx, w[i].ex);
		}
	}
	for (i = 0; i < 4; i++) {
		for (j = n + n - 1; j >= 0; j--) {
			Next[i][j] = min(Next[i][j], Next[i][j + 1]);
		}
	}
	for (i = 0; i < 4; i++) {
		for (j = 1; j <= n + n; j++) {
			Next[i][j] = min(Next[i][j], Next[(i + 1) % 4][0] + 2*n);
		}
	}
	for (i = 1; i <= CY; i++) {
		Go(0, i);
	}
}

Compilation message

hamburg.cpp: In function 'int main()':
hamburg.cpp:109:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  109 |  scanf("%d%d", &n, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
hamburg.cpp:111:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  111 |   scanf("%d%d%d%d", &w[i].bx, &w[i].by, &w[i].ex, &w[i].ey);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 360 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 9 ms 384 KB Output is correct
8 Correct 8 ms 416 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 10 ms 384 KB Output is correct
14 Incorrect 22 ms 512 KB Unexpected end of file - int32 expected
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 365 ms 7396 KB Output is correct
6 Correct 383 ms 7388 KB Output is correct
7 Correct 399 ms 7416 KB Output is correct
8 Correct 417 ms 7420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 462 ms 7292 KB Output is correct
6 Correct 424 ms 7348 KB Output is correct
7 Correct 389 ms 7416 KB Output is correct
8 Correct 405 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 371 ms 7288 KB Output is correct
14 Correct 413 ms 7416 KB Output is correct
15 Correct 403 ms 7416 KB Output is correct
16 Correct 382 ms 7416 KB Output is correct
17 Correct 388 ms 7396 KB Output is correct
18 Correct 386 ms 7396 KB Output is correct
19 Correct 460 ms 7392 KB Output is correct
20 Correct 470 ms 7480 KB Output is correct
21 Correct 528 ms 7392 KB Output is correct
22 Correct 628 ms 7464 KB Output is correct
23 Correct 414 ms 7416 KB Output is correct
24 Correct 377 ms 7300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 360 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 9 ms 384 KB Output is correct
8 Correct 8 ms 416 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 10 ms 384 KB Output is correct
14 Incorrect 22 ms 512 KB Unexpected end of file - int32 expected
15 Halted 0 ms 0 KB -