답안 #787408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787408 2023-07-19T06:59:15 Z 박상훈(#10032) 함박 스테이크 (JOI20_hamburg) C++17
21 / 100
3000 ms 27068 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
constexpr int INF = 1e9 + 100;

struct Rect{
	int x1, y1, x2, y2;
	Rect(){}
	Rect(int _x1, int _y1, int _x2, int _y2): x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}

	void read(){
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	}
	bool in(int x, int y){
		return x1 <= x && x <= x2 && y1 <= y && y <= y2;
	}
};

vector<pair<int, int>> ans;

void solve(vector<Rect> V, int k){
	if (k==0){
		if (!V.empty()) return;
		for (auto &[x, y]:ans) printf("%d %d\n", x, y);
		exit(0);
	}

	int lx = INF, rx = -INF, ly = INF, ry = -INF;
	for (auto &[x1, y1, x2, y2]:V){
		lx = min(lx, x2);
		rx = max(rx, x1);
		ly = min(ly, y2);
		ry = max(ry, y1);
	}

	if (V.empty()) lx = rx = ly = ry = 1;

	vector<pair<int, int>> C = {{lx, ly}, {lx, ry}, {rx, ly}, {rx, ry}};
	if (k==4){
		C.clear();

		vector<int> Y = {-INF};
		for (auto &[x1, y1, x2, y2]:V) if (x2 >= rx){
			Y.push_back(y1);
			Y.push_back(y2);
		}

		sort(Y.begin(), Y.end());
		Y.erase(unique(Y.begin(), Y.end()), Y.end());

		vector<int> sum(Y.size()), I(Y.size()), sum2(Y.size());
		for (auto &[x1, y1, x2, y2]:V) if (x2 >= rx){
			int i1 = lower_bound(Y.begin(), Y.end(), y1) - Y.begin();
			int i2 = lower_bound(Y.begin(), Y.end(), y2) - Y.begin();

			if (i2+1 < (int)sum.size()) sum[i2+1]--;
			sum[i1]++;

			if (x1==rx){
				sum2[i1]++;
				if (i2+1 < (int)sum.size()) sum2[i2+1]--;
			}
		}

		for (int i=1;i<(int)sum.size();i++) sum[i] += sum[i-1], I[i] = i, sum2[i] += sum2[i-1];

		sort(I.begin()+1, I.end(), [&](int i, int j){return sum[i] > sum[j];});
		for (int i0=1;i0<(int)I.size();i0++){
			if (!sum2[I[i0]]) continue;
			int y = Y[I[i0]];
			C.emplace_back(rx, y);
		}

		// for (auto &[x1, y1, x2, y2]:V) if (x2 >= rx){
		// 	C.emplace_back(rx, y1);
		// 	C.emplace_back(rx, y2);
		// 	// C.emplace_back(x2, y1);
		// 	// C.emplace_back(x2, y2);
		// }
	}
	for (auto &[x, y]:C){
		vector<Rect> nV;
		for (auto &R:V) if (!R.in(x, y)) nV.push_back(R);

		ans.emplace_back(x, y);
		solve(nV, k-1);
		ans.pop_back();
	}
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	
	vector<Rect> V(n);
	for (int i=0;i<n;i++) V[i].read();

	solve(V, k);

	printf("failed\n");
	return 0;
}

Compilation message

hamburg.cpp: In function 'int main()':
hamburg.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  scanf("%d %d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~
hamburg.cpp: In member function 'void Rect::read()':
hamburg.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 3 ms 584 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 7 ms 436 KB Output is correct
7 Correct 89 ms 604 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 186 ms 524 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 137 ms 596 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 299 ms 516 KB Output is correct
14 Correct 204 ms 572 KB Output is correct
15 Correct 104 ms 492 KB Output is correct
16 Correct 435 ms 556 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 356 ms 544 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 31 ms 496 KB Output is correct
21 Correct 197 ms 572 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 7 ms 592 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 80 ms 548 KB Output is correct
27 Correct 63 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 41 ms 504 KB Output is correct
31 Correct 36 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 21 ms 504 KB Output is correct
35 Correct 2 ms 548 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 576 KB Output is correct
38 Correct 2 ms 568 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 254 ms 604 KB Output is correct
41 Correct 8 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 3 ms 552 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 308 ms 544 KB Output is correct
48 Correct 4 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 44 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 105 ms 480 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 3 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 340 KB Output is correct
5 Correct 66 ms 6488 KB Output is correct
6 Correct 72 ms 6500 KB Output is correct
7 Correct 95 ms 6532 KB Output is correct
8 Correct 62 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 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 468 KB Output is correct
5 Correct 92 ms 9084 KB Output is correct
6 Correct 71 ms 8748 KB Output is correct
7 Correct 64 ms 8896 KB Output is correct
8 Correct 93 ms 17616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 3 ms 584 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 66 ms 9988 KB Output is correct
14 Correct 81 ms 10184 KB Output is correct
15 Correct 64 ms 8768 KB Output is correct
16 Correct 68 ms 8948 KB Output is correct
17 Correct 98 ms 11380 KB Output is correct
18 Correct 86 ms 8852 KB Output is correct
19 Correct 90 ms 11720 KB Output is correct
20 Correct 73 ms 15344 KB Output is correct
21 Correct 180 ms 27068 KB Output is correct
22 Correct 96 ms 18596 KB Output is correct
23 Correct 92 ms 21804 KB Output is correct
24 Correct 103 ms 24560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 7 ms 436 KB Output is correct
7 Correct 89 ms 604 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 186 ms 524 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 137 ms 596 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 299 ms 516 KB Output is correct
14 Correct 204 ms 572 KB Output is correct
15 Correct 104 ms 492 KB Output is correct
16 Correct 435 ms 556 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 356 ms 544 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 31 ms 496 KB Output is correct
21 Correct 197 ms 572 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 7 ms 592 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 80 ms 548 KB Output is correct
27 Correct 63 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 41 ms 504 KB Output is correct
31 Correct 36 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 21 ms 504 KB Output is correct
35 Correct 2 ms 548 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 576 KB Output is correct
38 Correct 2 ms 568 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 254 ms 604 KB Output is correct
41 Correct 8 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 3 ms 552 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 308 ms 544 KB Output is correct
48 Correct 4 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 44 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 105 ms 480 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 3 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 105 ms 15660 KB Output is correct
60 Execution timed out 3096 ms 14828 KB Time limit exceeded
61 Halted 0 ms 0 KB -