Submission #220300

# Submission time Handle Problem Language Result Execution time Memory
220300 2020-04-07T15:08:15 Z super_j6 Hamburg Steak (JOI20_hamburg) C++14
100 / 100
1198 ms 111856 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second

struct rect{
	int x, y, X, Y;
};

const int maxn = 200000;
int n, m, k;
int sz[4];
int cnt[maxn];
vector<rect> a;
vector<int> id;
vector<vector<int>> rin[4], rot[4];

int idx(int x){
	return lower_bound(id.begin(), id.end(), x) - id.begin();
}

rect bnd(vector<rect> v){
	rect ret = {m, m, 0, 0};
	for(rect i : v){
		ret.x = min(ret.x, i.X);
		ret.y = min(ret.y, i.Y);
		ret.X = max(ret.X, i.x);
		ret.Y = max(ret.Y, i.y);
	}
	return ret;
}

bool crs(int a, int b, int c){
	return a <= b && b <= c;
}

vector<pi> solve(vector<rect> v, int x){
	rect f = bnd(v);
	if(x == 1){
		if(f.x < f.X || f.y < f.Y) return {};
		else return {{f.x, f.y}};
	}
	vector<pi> pt = {{f.x, f.y}, {f.x, f.Y}, {f.X, f.y}, {f.X, f.Y}};
	for(pi p : pt){
		vector<rect> nv;
		for(rect i : v){
			if(!crs(i.x, p.f, i.X) || !crs(i.y, p.s, i.Y)) nv.push_back(i);
		}
		vector<pi> ret = solve(nv, x - 1);
		if(!ret.empty()){
			ret.push_back(p);
			return ret;
		}
	}
	return {};
}

int cur;
void add(int x){
	if(!cnt[x]) cur++;
	cnt[x]++;
}

void del(int x){
	if(cnt[x] == 1) cur--;
	cnt[x]--;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> k;
	
	a.resize(n);
	for(int i = 0; i < n; i++){
		cin >> a[i].x >> a[i].y >> a[i].X >> a[i].Y;
		id.push_back(a[i].x);
		id.push_back(a[i].y);
		id.push_back(a[i].X);
		id.push_back(a[i].Y);
	}
	
	sort(id.begin(), id.end());
	id.erase(unique(id.begin(), id.end()), id.end());
	m = id.size();
	
	for(int i = 0; i < n; i++){
		a[i].x = idx(a[i].x);
		a[i].y = idx(a[i].y);
		a[i].X = idx(a[i].X);
		a[i].Y = idx(a[i].Y);
 	}
 	
 	vector<pi> ans = solve(a, k);
 	
 	if(!ans.empty()){
 		for(pi i : ans) cout << id[i.f] << " " << id[i.s] << endl;
 		return 0;
 	}
 	
 	rect f = bnd(a);
 	sz[0] = sz[2] = f.X - f.x + 1, sz[1] = sz[3] = f.Y - f.y + 1;
 	for(int i = 0; i < 4; i++){
 		rin[i].resize(sz[i]);
 		rot[i].resize(sz[i]);
 	}
 	for(int i = 0; i < n; i++){
		if(crs(a[i].y, f.y, a[i].Y)){
			rin[0][max(0, a[i].x - f.x)].push_back(i);
			rot[0][min(sz[0] - 1, a[i].X - f.x)].push_back(i);
		}
		if(crs(a[i].x, f.X, a[i].X)){
			rin[1][max(0, a[i].y - f.y)].push_back(i);
			rot[1][min(sz[1] - 1, a[i].Y - f.y)].push_back(i);
		}
		if(crs(a[i].y, f.Y, a[i].Y)){
			rin[2][max(0, f.X - a[i].X)].push_back(i);
			rot[2][min(sz[2] - 1, f.X - a[i].x)].push_back(i);
		}
		if(crs(a[i].x, f.x, a[i].X)){
			rin[3][max(0, f.Y - a[i].Y)].push_back(i);
			rot[3][min(sz[3] - 1, f.Y - a[i].y)].push_back(i);
		}
 	}
 	for(int d = 0; d < 2; d++){
 		cur = 0;
      	for(int i = 0; i < n; i++) cnt[i] = 0;
	 	for(int it[4] = {0, -1, -1, -1}; it[0] < sz[0]; it[0]++){
	 		for(int j : rin[0][it[0]]) add(j);
	 		for(int t = 1; t < 4; t++){
	 			while(it[t] < sz[t] - 1){
	 				if(it[t] != -1){
	 					bool w = 1;
	 					for(int j : rot[t][it[t]]){
	 						if(cnt[j] == 1){
	 							w = 0;
	 							break;
	 						}
	 					}
	 					if(!w) break;
	 					for(int j : rot[t][it[t]]) del(j);
	 				}
	 				it[t]++;
	 				for(int j : rin[t][it[t]]) add(j);
	 			}
	 		}
	 		if(cur == n){
	 			if(d){
	 				cout << id[f.X - it[0]] << " " << id[f.y] << endl;
		 			cout << id[f.x] << " " << id[it[1] + f.y] << endl;
		 			cout << id[it[2] + f.x] << " " << id[f.Y] << endl;
		 			cout << id[f.X] << " " << id[f.Y - it[3]] << endl;
	 			}else{
		 			cout << id[it[0] + f.x] << " " << id[f.y] << endl;
		 			cout << id[f.X] << " " << id[it[1] + f.y] << endl;
		 			cout << id[f.X - it[2]] << " " << id[f.Y] << endl;
		 			cout << id[f.x] << " " << id[f.Y - it[3]] << endl;
	 			}
	 			return 0;
	 		}
	 		for(int j : rot[0][it[0]]) del(j);
	 	}
	 	swap(rin[1], rin[3]), swap(rot[1], rot[3]);
	 	for(int t = 0; t < 4; t++){
	 		reverse(rin[t].begin(), rin[t].end());
	 		reverse(rot[t].begin(), rot[t].end());
	 		for(int i = 0; i < sz[t]; i++) swap(rin[t][i], rot[t][i]);
	 	}
 	}
 	
 	cout << -1 << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 624 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 488 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 1076 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 6 ms 1200 KB Output is correct
18 Correct 4 ms 664 KB Output is correct
19 Correct 4 ms 636 KB Output is correct
20 Correct 6 ms 1316 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 4 ms 688 KB Output is correct
23 Correct 5 ms 1364 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 5 ms 1084 KB Output is correct
32 Correct 5 ms 992 KB Output is correct
33 Correct 5 ms 1060 KB Output is correct
34 Correct 7 ms 1012 KB Output is correct
35 Correct 5 ms 1340 KB Output is correct
36 Correct 5 ms 1088 KB Output is correct
37 Correct 6 ms 1416 KB Output is correct
38 Correct 7 ms 1460 KB Output is correct
39 Correct 5 ms 1192 KB Output is correct
40 Correct 5 ms 1008 KB Output is correct
41 Correct 5 ms 1144 KB Output is correct
42 Correct 5 ms 1260 KB Output is correct
43 Correct 5 ms 1232 KB Output is correct
44 Correct 5 ms 1236 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 6 ms 1328 KB Output is correct
47 Correct 7 ms 1200 KB Output is correct
48 Correct 6 ms 1400 KB Output is correct
49 Correct 6 ms 1284 KB Output is correct
50 Correct 5 ms 1176 KB Output is correct
51 Correct 6 ms 1392 KB Output is correct
52 Correct 5 ms 1000 KB Output is correct
53 Correct 7 ms 1216 KB Output is correct
54 Correct 6 ms 1360 KB Output is correct
55 Correct 6 ms 1256 KB Output is correct
56 Correct 5 ms 1268 KB Output is correct
57 Correct 6 ms 1188 KB Output is correct
58 Correct 5 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 328 ms 13060 KB Output is correct
6 Correct 325 ms 13028 KB Output is correct
7 Correct 337 ms 13028 KB Output is correct
8 Correct 325 ms 13028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 340 ms 14156 KB Output is correct
6 Correct 364 ms 13876 KB Output is correct
7 Correct 351 ms 14152 KB Output is correct
8 Correct 338 ms 17220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 624 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 361 ms 14896 KB Output is correct
14 Correct 347 ms 14616 KB Output is correct
15 Correct 346 ms 12964 KB Output is correct
16 Correct 336 ms 12936 KB Output is correct
17 Correct 369 ms 16496 KB Output is correct
18 Correct 342 ms 13028 KB Output is correct
19 Correct 401 ms 17016 KB Output is correct
20 Correct 345 ms 17676 KB Output is correct
21 Correct 425 ms 26252 KB Output is correct
22 Correct 366 ms 18444 KB Output is correct
23 Correct 361 ms 21088 KB Output is correct
24 Correct 361 ms 24236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 4 ms 488 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 1076 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 6 ms 1200 KB Output is correct
18 Correct 4 ms 664 KB Output is correct
19 Correct 4 ms 636 KB Output is correct
20 Correct 6 ms 1316 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 4 ms 688 KB Output is correct
23 Correct 5 ms 1364 KB Output is correct
24 Correct 4 ms 640 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 4 ms 640 KB Output is correct
31 Correct 5 ms 1084 KB Output is correct
32 Correct 5 ms 992 KB Output is correct
33 Correct 5 ms 1060 KB Output is correct
34 Correct 7 ms 1012 KB Output is correct
35 Correct 5 ms 1340 KB Output is correct
36 Correct 5 ms 1088 KB Output is correct
37 Correct 6 ms 1416 KB Output is correct
38 Correct 7 ms 1460 KB Output is correct
39 Correct 5 ms 1192 KB Output is correct
40 Correct 5 ms 1008 KB Output is correct
41 Correct 5 ms 1144 KB Output is correct
42 Correct 5 ms 1260 KB Output is correct
43 Correct 5 ms 1232 KB Output is correct
44 Correct 5 ms 1236 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 6 ms 1328 KB Output is correct
47 Correct 7 ms 1200 KB Output is correct
48 Correct 6 ms 1400 KB Output is correct
49 Correct 6 ms 1284 KB Output is correct
50 Correct 5 ms 1176 KB Output is correct
51 Correct 6 ms 1392 KB Output is correct
52 Correct 5 ms 1000 KB Output is correct
53 Correct 7 ms 1216 KB Output is correct
54 Correct 6 ms 1360 KB Output is correct
55 Correct 6 ms 1256 KB Output is correct
56 Correct 5 ms 1268 KB Output is correct
57 Correct 6 ms 1188 KB Output is correct
58 Correct 5 ms 1292 KB Output is correct
59 Correct 355 ms 18096 KB Output is correct
60 Correct 330 ms 16092 KB Output is correct
61 Correct 357 ms 16300 KB Output is correct
62 Correct 350 ms 15020 KB Output is correct
63 Correct 348 ms 16468 KB Output is correct
64 Correct 339 ms 13516 KB Output is correct
65 Correct 340 ms 16812 KB Output is correct
66 Correct 348 ms 15920 KB Output is correct
67 Correct 381 ms 24304 KB Output is correct
68 Correct 366 ms 22272 KB Output is correct
69 Correct 381 ms 19120 KB Output is correct
70 Correct 360 ms 23632 KB Output is correct
71 Correct 713 ms 32380 KB Output is correct
72 Correct 994 ms 96124 KB Output is correct
73 Correct 641 ms 31772 KB Output is correct
74 Correct 544 ms 32688 KB Output is correct
75 Correct 762 ms 72852 KB Output is correct
76 Correct 486 ms 30788 KB Output is correct
77 Correct 549 ms 30796 KB Output is correct
78 Correct 1099 ms 107300 KB Output is correct
79 Correct 568 ms 32280 KB Output is correct
80 Correct 562 ms 31252 KB Output is correct
81 Correct 930 ms 96448 KB Output is correct
82 Correct 485 ms 27760 KB Output is correct
83 Correct 424 ms 28844 KB Output is correct
84 Correct 417 ms 23260 KB Output is correct
85 Correct 537 ms 31524 KB Output is correct
86 Correct 419 ms 25176 KB Output is correct
87 Correct 472 ms 32268 KB Output is correct
88 Correct 534 ms 31312 KB Output is correct
89 Correct 794 ms 82116 KB Output is correct
90 Correct 1004 ms 104424 KB Output is correct
91 Correct 861 ms 79604 KB Output is correct
92 Correct 1198 ms 111856 KB Output is correct
93 Correct 928 ms 94828 KB Output is correct
94 Correct 1036 ms 97576 KB Output is correct
95 Correct 1088 ms 103568 KB Output is correct
96 Correct 900 ms 89176 KB Output is correct
97 Correct 939 ms 95836 KB Output is correct
98 Correct 924 ms 94320 KB Output is correct
99 Correct 820 ms 82804 KB Output is correct
100 Correct 1108 ms 103756 KB Output is correct
101 Correct 1008 ms 100876 KB Output is correct
102 Correct 698 ms 67476 KB Output is correct
103 Correct 1167 ms 110148 KB Output is correct
104 Correct 913 ms 77784 KB Output is correct
105 Correct 1043 ms 109200 KB Output is correct
106 Correct 1166 ms 102144 KB Output is correct
107 Correct 980 ms 92656 KB Output is correct
108 Correct 1164 ms 104400 KB Output is correct
109 Correct 1101 ms 105620 KB Output is correct
110 Correct 993 ms 99748 KB Output is correct
111 Correct 959 ms 92304 KB Output is correct
112 Correct 1119 ms 107808 KB Output is correct
113 Correct 818 ms 90240 KB Output is correct
114 Correct 804 ms 90192 KB Output is correct
115 Correct 820 ms 90176 KB Output is correct
116 Correct 802 ms 90064 KB Output is correct
117 Correct 613 ms 30984 KB Output is correct
118 Correct 616 ms 31136 KB Output is correct
119 Correct 627 ms 30980 KB Output is correct
120 Correct 614 ms 31080 KB Output is correct
121 Correct 625 ms 31168 KB Output is correct
122 Correct 633 ms 31000 KB Output is correct
123 Correct 615 ms 31028 KB Output is correct
124 Correct 612 ms 30964 KB Output is correct
125 Correct 740 ms 31084 KB Output is correct
126 Correct 629 ms 30976 KB Output is correct