Submission #258770

# Submission time Handle Problem Language Result Execution time Memory
258770 2020-08-06T14:27:25 Z Saboon Hamburg Steak (JOI20_hamburg) C++14
21 / 100
3000 ms 4320 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

multiset<int> Ls, Ds, Rs, Us;
int L[maxn], R[maxn], D[maxn], U[maxn];
int mark[maxn];
pair<int,int> ans[5];

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 <= n; i++)
			if (!mark[i])
				x = min(x, R[i]), y = min(y, U[i]);
		for (int i = 1; i <= n; i++)
			if (!mark[i])
				cor &= (L[i] <= x and x <= R[i] and D[i] <= y and y <= U[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 <= n; i++)
			if (!mark[i])
				x = min(x, R[i]), y1 = min(y1, U[i]), y2 = max(y2, D[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 <= n; i++)
			if (!mark[i])
				x1 = min(x1, R[i]), x2 = max(x2, L[i]), y1 = min(y1, U[i]), y2 = max(y2, D[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]);
		for (int i = 1; i <= n; i++){
			bool ret = check(n, k, x, U[i]);
			if (ret == true)
				return true;
		}
	}
	return false;
}

bool check(int n, int k, int x, int y){
	for (int i = 1; i <= n; i++)
		if (!mark[i] and L[i] <= x and x <= R[i] and D[i] <= y and y <= U[i])
			mark[i] = k;
	ans[k] = {x,y};
	bool ret = solve(n, k-1);
	if (ret == true)
		return true;
	for (int i = 1; i <= n; i++)
		if (mark[i] == k)
			mark[i] = 0;
	return false;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> L[i] >> D[i] >> R[i] >> U[i];
	bool solved = solve(n, k);
	assert(solved);
	for (int i = 1; i <= k; i++)
		cout << ans[i].first << " " << ans[i].second << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 412 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 16 ms 384 KB Output is correct
6 Correct 19 ms 384 KB Output is correct
7 Correct 338 ms 448 KB Output is correct
8 Correct 464 ms 452 KB Output is correct
9 Correct 161 ms 444 KB Output is correct
10 Correct 456 ms 452 KB Output is correct
11 Correct 761 ms 504 KB Output is correct
12 Correct 114 ms 384 KB Output is correct
13 Correct 529 ms 384 KB Output is correct
14 Correct 201 ms 384 KB Output is correct
15 Correct 241 ms 452 KB Output is correct
16 Correct 46 ms 448 KB Output is correct
17 Correct 862 ms 448 KB Output is correct
18 Correct 235 ms 384 KB Output is correct
19 Correct 389 ms 384 KB Output is correct
20 Correct 584 ms 448 KB Output is correct
21 Correct 228 ms 384 KB Output is correct
22 Correct 35 ms 384 KB Output is correct
23 Correct 33 ms 384 KB Output is correct
24 Correct 81 ms 448 KB Output is correct
25 Correct 205 ms 444 KB Output is correct
26 Correct 61 ms 384 KB Output is correct
27 Correct 14 ms 384 KB Output is correct
28 Correct 32 ms 444 KB Output is correct
29 Correct 163 ms 448 KB Output is correct
30 Correct 68 ms 444 KB Output is correct
31 Correct 502 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 826 ms 444 KB Output is correct
34 Correct 96 ms 448 KB Output is correct
35 Correct 49 ms 384 KB Output is correct
36 Correct 116 ms 384 KB Output is correct
37 Correct 827 ms 504 KB Output is correct
38 Correct 311 ms 448 KB Output is correct
39 Correct 299 ms 448 KB Output is correct
40 Correct 77 ms 384 KB Output is correct
41 Correct 77 ms 384 KB Output is correct
42 Correct 429 ms 504 KB Output is correct
43 Correct 31 ms 384 KB Output is correct
44 Correct 31 ms 384 KB Output is correct
45 Correct 35 ms 384 KB Output is correct
46 Correct 581 ms 448 KB Output is correct
47 Correct 300 ms 384 KB Output is correct
48 Correct 5 ms 416 KB Output is correct
49 Correct 318 ms 384 KB Output is correct
50 Correct 648 ms 508 KB Output is correct
51 Correct 312 ms 384 KB Output is correct
52 Correct 4 ms 384 KB Output is correct
53 Correct 7 ms 384 KB Output is correct
54 Correct 565 ms 448 KB Output is correct
55 Correct 424 ms 384 KB Output is correct
56 Correct 415 ms 448 KB Output is correct
57 Correct 407 ms 384 KB Output is correct
58 Correct 852 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 95 ms 3448 KB Output is correct
6 Correct 93 ms 3448 KB Output is correct
7 Correct 93 ms 3448 KB Output is correct
8 Correct 111 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 102 ms 4252 KB Output is correct
6 Correct 104 ms 4184 KB Output is correct
7 Correct 105 ms 4252 KB Output is correct
8 Correct 104 ms 4168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 412 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 98 ms 4292 KB Output is correct
14 Correct 106 ms 4264 KB Output is correct
15 Correct 98 ms 4192 KB Output is correct
16 Correct 104 ms 4260 KB Output is correct
17 Correct 105 ms 4216 KB Output is correct
18 Correct 101 ms 4216 KB Output is correct
19 Correct 104 ms 4216 KB Output is correct
20 Correct 104 ms 4216 KB Output is correct
21 Correct 172 ms 4216 KB Output is correct
22 Correct 122 ms 4168 KB Output is correct
23 Correct 133 ms 4320 KB Output is correct
24 Correct 115 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 16 ms 384 KB Output is correct
6 Correct 19 ms 384 KB Output is correct
7 Correct 338 ms 448 KB Output is correct
8 Correct 464 ms 452 KB Output is correct
9 Correct 161 ms 444 KB Output is correct
10 Correct 456 ms 452 KB Output is correct
11 Correct 761 ms 504 KB Output is correct
12 Correct 114 ms 384 KB Output is correct
13 Correct 529 ms 384 KB Output is correct
14 Correct 201 ms 384 KB Output is correct
15 Correct 241 ms 452 KB Output is correct
16 Correct 46 ms 448 KB Output is correct
17 Correct 862 ms 448 KB Output is correct
18 Correct 235 ms 384 KB Output is correct
19 Correct 389 ms 384 KB Output is correct
20 Correct 584 ms 448 KB Output is correct
21 Correct 228 ms 384 KB Output is correct
22 Correct 35 ms 384 KB Output is correct
23 Correct 33 ms 384 KB Output is correct
24 Correct 81 ms 448 KB Output is correct
25 Correct 205 ms 444 KB Output is correct
26 Correct 61 ms 384 KB Output is correct
27 Correct 14 ms 384 KB Output is correct
28 Correct 32 ms 444 KB Output is correct
29 Correct 163 ms 448 KB Output is correct
30 Correct 68 ms 444 KB Output is correct
31 Correct 502 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 826 ms 444 KB Output is correct
34 Correct 96 ms 448 KB Output is correct
35 Correct 49 ms 384 KB Output is correct
36 Correct 116 ms 384 KB Output is correct
37 Correct 827 ms 504 KB Output is correct
38 Correct 311 ms 448 KB Output is correct
39 Correct 299 ms 448 KB Output is correct
40 Correct 77 ms 384 KB Output is correct
41 Correct 77 ms 384 KB Output is correct
42 Correct 429 ms 504 KB Output is correct
43 Correct 31 ms 384 KB Output is correct
44 Correct 31 ms 384 KB Output is correct
45 Correct 35 ms 384 KB Output is correct
46 Correct 581 ms 448 KB Output is correct
47 Correct 300 ms 384 KB Output is correct
48 Correct 5 ms 416 KB Output is correct
49 Correct 318 ms 384 KB Output is correct
50 Correct 648 ms 508 KB Output is correct
51 Correct 312 ms 384 KB Output is correct
52 Correct 4 ms 384 KB Output is correct
53 Correct 7 ms 384 KB Output is correct
54 Correct 565 ms 448 KB Output is correct
55 Correct 424 ms 384 KB Output is correct
56 Correct 415 ms 448 KB Output is correct
57 Correct 407 ms 384 KB Output is correct
58 Correct 852 ms 384 KB Output is correct
59 Execution timed out 3073 ms 4216 KB Time limit exceeded
60 Halted 0 ms 0 KB -