Submission #392401

# Submission time Handle Problem Language Result Execution time Memory
392401 2021-04-21T04:12:09 Z oolimry None (KOI16_laser) C++17
100 / 100
259 ms 63408 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) x.size())
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x, y) cerr << #x << " is " << x << ", " << #y << " is " << y << endl;
typedef long long lint;
typedef pair<lint, lint> ii;

const int RED = -1, BLUE = 2;

struct point{
	lint x, y, id, color;
	point operator -(point &b){ return {x-b.x, y-b.y, -2, -1}; }
};
lint cross(point a, point b){
	return (a.x*b.y - a.y*b.x);
}
lint orientation(point a, point b, point c){
	return cross(c-a,b-a);
}

vector<point> allpoints;

void reorient(vector<point> &points, int id){
	swap(points[0], points[id]);
	sort(points.begin()+1, points.end(), [&](point a, point b){
		return orientation(points[0], a, b) > 0;
	});
}

vector<int> ans[1005];
void add(point a, point b){
	if(a.color == RED) swap(a,b);
	ans[a.id].push_back(b.id);
}

void solve(vector<point> points){
	int n = sz(points);
	if(n == 0) return;
	
	sort(all(points), [&](point &a, point &b){ return ii(a.y,a.x) < ii(b.y,b.x); } );
	reorient(points, 0);
	
	//for(point p : points) show2(p.color, p.id);
	//show("FFFFFFFFFFF");
	
	if(points[0].color == RED and points[1].color == RED and points[n-1].color == RED){
		vector<point> split[2];
		int cnt = 0;
		int acc = 0;
		for(int i = 1;i < n;i++){
			point p = points[i];
			acc += p.color;
			split[cnt].push_back(p);
			
			if(cnt == 0){
				if(acc == 0){
					cnt++;
					split[1].push_back(points[0]);
				}
				else if(acc == 1){
					cnt++;
					split[0].push_back(points[0]);
				}
			}
		}
		
		solve(split[0]);
		solve(split[1]);
	}
	else{
		if(points[1].color == BLUE) reorient(points, 1);
		else if(points[n-1].color == BLUE) reorient(points, n-1);
		
		//show("HERE1");
		int acc = 0;
		int cnt = 0;
		vector<point> split[3];
		for(int i = 1;i < n;i++){
			point p = points[i];
			
			if(acc == 0 and p.color == RED and cnt < 2){
				cnt++;
				add(points[0], p);
			}
			else{
				acc += p.color;
				split[cnt].push_back(p);
			}
		}
		
		solve(split[0]);
		solve(split[1]);
		solve(split[2]);
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	for(int i = 1;i <= n;i++){
		int x, y; cin >> x >> y;
		allpoints.push_back({x,y,i,BLUE});
	}
	for(int i = 1;i <= 2*n;i++){
		int x, y; cin >> x >> y;
		allpoints.push_back({x,y,i,RED});
	}
	
	solve(allpoints);
	
	for(int i = 1;i <= n;i++){
		cout << ans[i][0] << " " << ans[i][1] << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 472 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 3 ms 1368 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 3 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 472 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 3 ms 1368 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 2 ms 844 KB Output is correct
38 Correct 3 ms 1484 KB Output is correct
39 Correct 2 ms 716 KB Output is correct
40 Correct 2 ms 728 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 2 ms 712 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 1 ms 464 KB Output is correct
48 Correct 1 ms 588 KB Output is correct
49 Correct 2 ms 844 KB Output is correct
50 Correct 2 ms 716 KB Output is correct
51 Correct 3 ms 1100 KB Output is correct
52 Correct 3 ms 972 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 2 ms 844 KB Output is correct
55 Correct 2 ms 844 KB Output is correct
56 Correct 2 ms 844 KB Output is correct
57 Correct 1 ms 460 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 2 ms 588 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 2 ms 548 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 2 ms 600 KB Output is correct
65 Correct 2 ms 588 KB Output is correct
66 Correct 2 ms 588 KB Output is correct
67 Correct 2 ms 716 KB Output is correct
68 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 472 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 3 ms 1368 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 2 ms 844 KB Output is correct
38 Correct 3 ms 1484 KB Output is correct
39 Correct 2 ms 716 KB Output is correct
40 Correct 2 ms 728 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 2 ms 712 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 1 ms 464 KB Output is correct
48 Correct 1 ms 588 KB Output is correct
49 Correct 2 ms 844 KB Output is correct
50 Correct 2 ms 716 KB Output is correct
51 Correct 3 ms 1100 KB Output is correct
52 Correct 3 ms 972 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 2 ms 844 KB Output is correct
55 Correct 2 ms 844 KB Output is correct
56 Correct 2 ms 844 KB Output is correct
57 Correct 1 ms 460 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 2 ms 588 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 2 ms 548 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 2 ms 600 KB Output is correct
65 Correct 2 ms 588 KB Output is correct
66 Correct 2 ms 588 KB Output is correct
67 Correct 2 ms 716 KB Output is correct
68 Correct 2 ms 604 KB Output is correct
69 Correct 59 ms 13720 KB Output is correct
70 Correct 35 ms 9076 KB Output is correct
71 Correct 56 ms 15044 KB Output is correct
72 Correct 36 ms 9204 KB Output is correct
73 Correct 29 ms 6668 KB Output is correct
74 Correct 24 ms 4940 KB Output is correct
75 Correct 42 ms 10216 KB Output is correct
76 Correct 47 ms 11068 KB Output is correct
77 Correct 27 ms 5944 KB Output is correct
78 Correct 34 ms 7760 KB Output is correct
79 Correct 259 ms 63408 KB Output is correct
80 Correct 239 ms 60972 KB Output is correct
81 Correct 254 ms 62528 KB Output is correct
82 Correct 172 ms 49564 KB Output is correct
83 Correct 192 ms 49240 KB Output is correct
84 Correct 199 ms 49344 KB Output is correct
85 Correct 195 ms 49252 KB Output is correct
86 Correct 193 ms 49220 KB Output is correct
87 Correct 43 ms 10052 KB Output is correct
88 Correct 43 ms 9348 KB Output is correct
89 Correct 71 ms 21956 KB Output is correct
90 Correct 20 ms 4020 KB Output is correct
91 Correct 33 ms 7248 KB Output is correct
92 Correct 30 ms 6464 KB Output is correct
93 Correct 23 ms 4784 KB Output is correct
94 Correct 43 ms 10104 KB Output is correct
95 Correct 26 ms 5772 KB Output is correct
96 Correct 23 ms 4740 KB Output is correct
97 Correct 33 ms 5200 KB Output is correct
98 Correct 22 ms 4664 KB Output is correct