답안 #258843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258843 2020-08-06T15:42:03 Z Saboon 함박 스테이크 (JOI20_hamburg) C++14
21 / 100
2818 ms 12780 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;

const int maxn = 2e5 + 10;
const int inf = 1e9 + 1;

int L[maxn], R[maxn], D[maxn], U[maxn];
int mark[maxn];
pair<int,int> ans[5];
int rot = 0;
int p[maxn], q[6][maxn], sz = 0;

inline bool check(int,int,int,int);

bool solve(int n, int k){
	if (k == 1){
		bool cor = 1;
		int x = inf-1, y = inf-1;
		for (int i = 1; i <= sz; i++)
			x = min(x, R[p[i]]), y = min(y, U[p[i]]);
		for (int i = 1; i <= sz; i++)
			cor &= (L[p[i]] <= x and x <= R[p[i]] and D[p[i]] <= y and y <= U[p[i]]);
		if (cor)
			ans[k] = {x,y};
		return cor;
	}
	if (k == 2){
		int x = inf-1, y1 = inf-1, y2 = 1;
		for (int i = 1; i <= sz; i++)
			x = min(x, R[p[i]]), y1 = min(y1, U[p[i]]), y2 = max(y2, D[p[i]]);
		bool ret = check(n, k, x, y1);
		if (ret == true)
			return true;
		ret = check(n, k, x, y2);
		return ret;
	}
	if (k == 3){
		int x1 = inf-1, x2 = 1, y1 = inf-1, y2 = 1;
		for (int i = 1; i <= sz; i++)
			x1 = min(x1, R[p[i]]), x2 = max(x2, L[p[i]]), y1 = min(y1, U[p[i]]), y2 = max(y2, D[p[i]]);
		bool ret = check(n, k, x1, y1);
		if (ret == true)
			return true;
		ret = check(n, k, x1, y2);
		if (ret == true)
			return true;
		ret = check(n, k, x2, y1);
		if (ret == true)
			return true;
		ret = check(n, k, x2, y2);
		return ret;
	}
	if (k == 4){
		int x = inf-1;
		for (int i = 1; i <= n; i++)
			x = min(x, R[i]);
		vector<pair<int,int>> seg;
		for (int i = 1; i <= n; i++)
			if (L[i] <= x)
				seg.push_back({D[i],i});
		sort(seg.rbegin(), seg.rend());
		int minl = inf;
		for (auto it : seg){
			int idx = it.second;
			if (U[idx] < minl){
				bool ret = check(n, k, x, U[idx]);
				if (ret)
					return true;
				minl = U[idx];
			}
		}
		int cnt = 0;
		for (int i = 1; i <= n; i++)
			if (L[i] <= x)
				seg[cnt++] = {U[i],i};
		sort(seg.begin(), seg.end());
		int maxr = 0;
		for (auto it : seg){
			int idx = it.second;
			if (maxr < D[idx]){
				bool ret = check(n, k, x, D[idx]);
				if (ret)
					return true;
				maxr = D[idx];
			}
		}
		if (rot < 4){
			for (int i = 1; i <= n; i++){
				int l = L[i], r = R[i], u = U[i], d = D[i];
				U[i] = inf - l, D[i] = inf - r, L[i] = d, R[i] = u;
			}
			rot ++;
			bool ret = solve(n,k);
			if (ret == true){
				for (int i = 1; i <= k; i++){
					int x = ans[i].first, y = ans[i].second;
					ans[i] = {inf - y, x};
				}
				return true;
			}
		}
	}
	return false;
}

inline bool check(int n, int k, int x, int y){
	for (int i = 1; i <= sz; i++)
		q[k][i] = p[i];
	int then = 0;
	for (int it = 1; it <= sz; it++){
		int i = p[it];
		if (L[i] > x or x > R[i] or D[i] > y or y > U[i])
			p[++then] = i;
	}
	int tmp = sz;
	sz = then;
	ans[k] = {x,y};
	bool ret = solve(n, k-1);
	if (ret == true)
		return true;
	for (int i = 1; i <= tmp; i++)
		p[i] = q[k][i];
	sz = tmp;
	return false;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d%d%d%d", &L[i], &D[i], &R[i], &U[i]);
	for (int i = 1; i <= n; i++)
		p[++sz] = i;
	bool solved = solve(n, k);
	assert(solved);
	for (int i = 1; i <= k; i++)
		printf("%d %d\n", ans[i].first, ans[i].second);
}

Compilation message

hamburg.cpp: In function 'int main()':
hamburg.cpp:132:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  132 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
hamburg.cpp:134:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  134 |   scanf("%d%d%d%d", &L[i], &D[i], &R[i], &U[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 5 ms 416 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 5 ms 488 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 544 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 8 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 6 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 15 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 11 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 6 ms 512 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 4 ms 512 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 3 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 6 ms 512 KB Output is correct
57 Correct 7 ms 512 KB Output is correct
58 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 143 ms 4216 KB Output is correct
6 Correct 141 ms 4224 KB Output is correct
7 Correct 141 ms 4216 KB Output is correct
8 Correct 139 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 141 ms 5152 KB Output is correct
6 Correct 144 ms 4992 KB Output is correct
7 Correct 154 ms 5080 KB Output is correct
8 Correct 162 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 141 ms 5496 KB Output is correct
14 Correct 160 ms 5356 KB Output is correct
15 Correct 150 ms 5240 KB Output is correct
16 Correct 182 ms 5248 KB Output is correct
17 Correct 178 ms 5496 KB Output is correct
18 Correct 152 ms 5240 KB Output is correct
19 Correct 168 ms 5496 KB Output is correct
20 Correct 162 ms 5472 KB Output is correct
21 Correct 187 ms 5812 KB Output is correct
22 Correct 149 ms 5624 KB Output is correct
23 Correct 143 ms 5628 KB Output is correct
24 Correct 200 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 5 ms 416 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 5 ms 488 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 544 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 8 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 7 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 6 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 4 ms 512 KB Output is correct
37 Correct 15 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 11 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 6 ms 512 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 4 ms 512 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 3 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 6 ms 512 KB Output is correct
57 Correct 7 ms 512 KB Output is correct
58 Correct 6 ms 512 KB Output is correct
59 Correct 288 ms 6896 KB Output is correct
60 Correct 329 ms 8044 KB Output is correct
61 Correct 216 ms 6768 KB Output is correct
62 Correct 253 ms 7808 KB Output is correct
63 Correct 289 ms 6908 KB Output is correct
64 Correct 200 ms 7532 KB Output is correct
65 Correct 778 ms 7408 KB Output is correct
66 Correct 795 ms 7656 KB Output is correct
67 Correct 677 ms 7028 KB Output is correct
68 Correct 1382 ms 7536 KB Output is correct
69 Correct 1176 ms 7532 KB Output is correct
70 Correct 589 ms 7024 KB Output is correct
71 Correct 655 ms 7536 KB Output is correct
72 Correct 638 ms 7284 KB Output is correct
73 Correct 488 ms 6940 KB Output is correct
74 Correct 1198 ms 7280 KB Output is correct
75 Correct 470 ms 7272 KB Output is correct
76 Correct 1381 ms 7788 KB Output is correct
77 Correct 457 ms 7468 KB Output is correct
78 Correct 1787 ms 8176 KB Output is correct
79 Correct 1189 ms 7408 KB Output is correct
80 Correct 434 ms 7124 KB Output is correct
81 Correct 1282 ms 7392 KB Output is correct
82 Correct 487 ms 7532 KB Output is correct
83 Correct 278 ms 7024 KB Output is correct
84 Correct 1557 ms 7912 KB Output is correct
85 Correct 359 ms 7112 KB Output is correct
86 Correct 216 ms 7152 KB Output is correct
87 Correct 2315 ms 7408 KB Output is correct
88 Correct 313 ms 7404 KB Output is correct
89 Correct 427 ms 7152 KB Output is correct
90 Correct 1159 ms 7152 KB Output is correct
91 Correct 752 ms 7152 KB Output is correct
92 Correct 474 ms 7028 KB Output is correct
93 Correct 487 ms 7408 KB Output is correct
94 Correct 907 ms 7452 KB Output is correct
95 Correct 2140 ms 8168 KB Output is correct
96 Correct 710 ms 7560 KB Output is correct
97 Correct 1315 ms 7280 KB Output is correct
98 Correct 1146 ms 7268 KB Output is correct
99 Correct 1061 ms 7416 KB Output is correct
100 Correct 732 ms 7316 KB Output is correct
101 Correct 1983 ms 8864 KB Output is correct
102 Correct 299 ms 7500 KB Output is correct
103 Correct 1408 ms 7408 KB Output is correct
104 Correct 1100 ms 8736 KB Output is correct
105 Correct 712 ms 7408 KB Output is correct
106 Correct 347 ms 7156 KB Output is correct
107 Correct 1052 ms 7532 KB Output is correct
108 Correct 619 ms 7084 KB Output is correct
109 Correct 1840 ms 8140 KB Output is correct
110 Correct 964 ms 7132 KB Output is correct
111 Correct 1330 ms 7404 KB Output is correct
112 Correct 428 ms 7132 KB Output is correct
113 Correct 772 ms 7512 KB Output is correct
114 Correct 789 ms 7444 KB Output is correct
115 Correct 718 ms 7324 KB Output is correct
116 Correct 761 ms 7532 KB Output is correct
117 Runtime error 2818 ms 12780 KB Execution killed with signal 11 (could be triggered by violating memory limits)
118 Halted 0 ms 0 KB -