답안 #404830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404830 2021-05-15T05:53:49 Z maomao90 레이저 센서 (KOI16_laser) C++14
100 / 100
219 ms 48068 KB
#include <bits/stdc++.h> 
using namespace std;

#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 3005

struct pt {
	ll x, y; int color;
	int id;
	pt() {
		x = 0; y = 0; color = 0; id = 0;
	}
	pt(ll x, ll y): x(x), y(y), color(0), id(0) {}
	pt(ll x, ll y, int color, int id): x(x), y(y), color(color), id(id) {}
	pt operator-(const pt& other) const {
		return pt(x - other.x, y - other.y);
	}
	bool operator==(const pt& r) const {
		return x == r.x && y == r.y && color == r.color && id == r.id;
	}
};
ll cross(pt a, pt b) {
	return a.x * b.y - a.y * b.x;
}
// positive if c is to the right/top of line ab
ll orient(pt a, pt b, pt c) {
	return cross(b - a, c - a);
}

int n;
vector<pt> points;
ii ans[MAXN];

void order(vector<pt>& points) {
	sort(points.begin() + 1, points.end(), [&] (pt l, pt r) {
			// sort clockwise
			return orient(points[0], l, r) < 0;
			});
	//REP (i, 0, points.size()) {
		//printf(" %lld %lld %d\n", points[i].x, points[i].y, points[i].id);
	//}
}

void solve(vector<pt> points) {
	if (points.size() == 0) {
	   	return;
	}
	sort(ALL(points), [&] (pt l, pt r) {
			return l.y < r.y;
			});
	order(points);
	if (points[0].color == 2 || points[1].color == 2 || points.back().color == 2) {
		if (points[1].color == 2) {
			swap(points[1], points[0]);
		} else if (points.back().color == 2) {
			swap(points[points.size() - 1], points[0]);
		}
		order(points);
		int cnt = 0;
		pt f, s;
		int i = 0;
		vector<pt> res[5];
		for (int j = 1; j < points.size(); j++) {
			pt point = points[j];
			cnt += point.color;
			if (cnt == -1 && i == 0 && point.color == -1) {
				f = point;
				i++;
			} else if (cnt == -2 && i == 1 && point.color == -1) {
				s = point;
				i++;
			} else {
				res[i].pb(point);
			}
		}
		ans[points[0].id] = MP(f.id, s.id);
		REP (j, 0, 3) {
			solve(res[j]);
		}
	} else {
		int i = 0;
		int cnt = 0;
		vector<pt> res[5];
		for (int j = 1; j < points.size(); j++) {
			pt point = points[j];
			cnt += point.color;
			res[i].pb(point);
			if (i == 0 && cnt == 0) {
				i++;
				res[i].pb(points[0]);
			} else if (i == 0 && cnt == 1) {
				res[i].pb(points[0]);
				i++;
			}
		}
		REP (j, 0, 2) {
			solve(res[j]);
		}
	}
}

int main() {
	scanf("%d", &n);
	REP (i, 0, n) {
		pt temp;
		scanf("%lld%lld", &temp.x, &temp.y);
		temp.id = i;
		temp.color = 2;
		points.pb(temp);
	}
	REP (i, n, 3 * n) {
		pt temp;
		scanf("%lld%lld", &temp.x, &temp.y);
		temp.id = i;
		temp.color = -1;
		points.pb(temp);
	}
	solve(points);
	REP (i, 0, n) {
		printf("%d %d\n", ans[i].FI - n + 1, ans[i].SE - n + 1);
	}
	return 0;
}

Compilation message

laser.cpp: In function 'void solve(std::vector<pt>)':
laser.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for (int j = 1; j < points.size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~
laser.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |   for (int j = 1; j < points.size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~
laser.cpp: In function 'int main()':
laser.cpp:123:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
laser.cpp:126:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |   scanf("%lld%lld", &temp.x, &temp.y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
laser.cpp:133:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |   scanf("%lld%lld", &temp.x, &temp.y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 1100 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 2 ms 716 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 3 ms 1100 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 2 ms 716 KB Output is correct
38 Correct 3 ms 1100 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 2 ms 716 KB Output is correct
50 Correct 2 ms 588 KB Output is correct
51 Correct 4 ms 844 KB Output is correct
52 Correct 3 ms 716 KB Output is correct
53 Correct 2 ms 716 KB Output is correct
54 Correct 2 ms 716 KB Output is correct
55 Correct 2 ms 716 KB Output is correct
56 Correct 2 ms 716 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 2 ms 460 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 360 KB Output is correct
62 Correct 2 ms 460 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 2 ms 460 KB Output is correct
65 Correct 2 ms 460 KB Output is correct
66 Correct 2 ms 460 KB Output is correct
67 Correct 2 ms 588 KB Output is correct
68 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 3 ms 1100 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 2 ms 716 KB Output is correct
38 Correct 3 ms 1100 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 2 ms 716 KB Output is correct
50 Correct 2 ms 588 KB Output is correct
51 Correct 4 ms 844 KB Output is correct
52 Correct 3 ms 716 KB Output is correct
53 Correct 2 ms 716 KB Output is correct
54 Correct 2 ms 716 KB Output is correct
55 Correct 2 ms 716 KB Output is correct
56 Correct 2 ms 716 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 2 ms 460 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 360 KB Output is correct
62 Correct 2 ms 460 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 2 ms 460 KB Output is correct
65 Correct 2 ms 460 KB Output is correct
66 Correct 2 ms 460 KB Output is correct
67 Correct 2 ms 588 KB Output is correct
68 Correct 2 ms 460 KB Output is correct
69 Correct 49 ms 10556 KB Output is correct
70 Correct 31 ms 6988 KB Output is correct
71 Correct 48 ms 11436 KB Output is correct
72 Correct 31 ms 6972 KB Output is correct
73 Correct 25 ms 5060 KB Output is correct
74 Correct 22 ms 3740 KB Output is correct
75 Correct 37 ms 7828 KB Output is correct
76 Correct 42 ms 8260 KB Output is correct
77 Correct 23 ms 4424 KB Output is correct
78 Correct 29 ms 5864 KB Output is correct
79 Correct 219 ms 48068 KB Output is correct
80 Correct 205 ms 46156 KB Output is correct
81 Correct 216 ms 47492 KB Output is correct
82 Correct 178 ms 37128 KB Output is correct
83 Correct 167 ms 37444 KB Output is correct
84 Correct 171 ms 37500 KB Output is correct
85 Correct 169 ms 37412 KB Output is correct
86 Correct 168 ms 37412 KB Output is correct
87 Correct 37 ms 7620 KB Output is correct
88 Correct 37 ms 7308 KB Output is correct
89 Correct 67 ms 16752 KB Output is correct
90 Correct 17 ms 3020 KB Output is correct
91 Correct 28 ms 5512 KB Output is correct
92 Correct 27 ms 4984 KB Output is correct
93 Correct 21 ms 3660 KB Output is correct
94 Correct 36 ms 7720 KB Output is correct
95 Correct 23 ms 4428 KB Output is correct
96 Correct 20 ms 3592 KB Output is correct
97 Correct 24 ms 3868 KB Output is correct
98 Correct 21 ms 3528 KB Output is correct