답안 #38428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38428 2018-01-04T05:51:33 Z kajebiii 레이저 센서 (KOI16_laser) C++14
100 / 100
166 ms 36996 KB
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

int sign(ll x) {return (x>0) - (x<0);}
struct PT{
	int x, y, c, ix;
	PT() {}
	PT(int xx, int yy) : x(xx), y(yy), c(-10), ix(-10) {}
	PT(int xx, int yy, int cc, int ii) : x(xx), y(yy), c(cc), ix(ii) {}
	PT operator-(const PT &o) const{return PT(x-o.x, y-o.y);}
	ll cross(const PT &o) const{return 1ll*x*o.y - 1ll*y*o.x;}
	ll cross(const PT &a, const PT &b) const{return (a-*this).cross(b-*this);}
	int ccw(const PT &o) const{return sign(cross(o));}
	int ccw(const PT &a, const PT &b) const{return sign(cross(a, b));}
};

const int MAX_N = 1e3 + 10;

int N;
vector<PT> Ps;
int Ans[MAX_N][2];

void getAns(vector<PT> &ps) {
	if(SZ(ps) == 0) return;
	int n = SZ(ps);
	for(int i=1; i<n; i++) if(ps[0].y > ps[i].y || ps[0].y == ps[i].y && ps[0].x > ps[i].x) swap(ps[0], ps[i]);
	sort(ps.begin()+1, ps.end(), [&](PT &a, PT &b) {return ps[0].ccw(a, b) > 0;});
	int cix = -1;
	for(int i=n-1; i<=n+1; i++) if(ps[i%n].c == 2) {cix = i%n; break;}
	if(cix != -1) {
		swap(ps[0], ps[cix]);
		sort(ps.begin()+1, ps.end(), [&](PT &a, PT &b) {return ps[0].ccw(a, b) > 0;});
		int ix = ps[0].ix;
		int now = 2, limit = 1, cnt = 0;
		vector<PT> nps[3];
		for(int i=1; i<n; i++) {
			now += ps[i].c;
			if(ps[i].c == -1 && now == limit && limit != -1) {
				Ans[ix][cnt] = ps[i].ix;
				limit--; cnt++;
			}else nps[cnt].push_back(ps[i]);
		}
		for(int i=0; i<3; i++) getAns(nps[i]);
	}else{
		int now = 0, cnt = 0;
		vector<PT> nps[2]; 
		for(int i=0; i<n; i++) {
			now += ps[i%n].c;
			nps[cnt].push_back(ps[i%n]);
			if(cnt == 0 && now == 0) cnt++;
		}
		if(SZ(nps[1]) == 0) {
			nps[0].clear(); nps[1].clear();
			now = cnt = 0;
			for(int i=n; i>=1; i--) {
				now += ps[i%n].c;
				nps[cnt].push_back(ps[i%n]);
				if(cnt == 0 && now == 0) cnt++;
			}
		}
		for(int i=0; i<2; i++) getAns(nps[i]);
	}
}
int main() {
	cin >> N;
	for(int i=0; i<3*N; i++) {
		int x, y; scanf("%d%d", &x, &y);
		Ps.emplace_back(x, y, i<N?2:-1, i<N?i:i-N);
	}
	getAns(Ps);

	for(int i=0; i<N; i++) printf("%d %d\n", Ans[i][0]+1, Ans[i][1]+1);
	return 0;
}

Compilation message

laser.cpp: In function 'void getAns(std::vector<PT>&)':
laser.cpp:36:68: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  for(int i=1; i<n; i++) if(ps[0].y > ps[i].y || ps[0].y == ps[i].y && ps[0].x > ps[i].x) swap(ps[0], ps[i]);
                                                                    ^
laser.cpp: In function 'int main()':
laser.cpp:77:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2032 KB Output is correct
2 Correct 0 ms 2032 KB Output is correct
3 Correct 0 ms 2032 KB Output is correct
4 Correct 0 ms 2032 KB Output is correct
5 Correct 0 ms 2032 KB Output is correct
6 Correct 0 ms 2032 KB Output is correct
7 Correct 0 ms 2032 KB Output is correct
8 Correct 0 ms 2032 KB Output is correct
9 Correct 0 ms 2032 KB Output is correct
10 Correct 0 ms 2032 KB Output is correct
11 Correct 0 ms 2032 KB Output is correct
12 Correct 0 ms 2032 KB Output is correct
13 Correct 0 ms 2032 KB Output is correct
14 Correct 0 ms 2032 KB Output is correct
15 Correct 0 ms 2032 KB Output is correct
16 Correct 0 ms 2032 KB Output is correct
17 Correct 0 ms 2032 KB Output is correct
18 Correct 0 ms 2032 KB Output is correct
19 Correct 0 ms 2032 KB Output is correct
20 Correct 0 ms 2032 KB Output is correct
21 Correct 0 ms 2032 KB Output is correct
22 Correct 0 ms 2032 KB Output is correct
23 Correct 0 ms 2032 KB Output is correct
24 Correct 0 ms 2032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2164 KB Output is correct
2 Correct 0 ms 2032 KB Output is correct
3 Correct 0 ms 2164 KB Output is correct
4 Correct 0 ms 2164 KB Output is correct
5 Correct 0 ms 2032 KB Output is correct
6 Correct 0 ms 2164 KB Output is correct
7 Correct 0 ms 2032 KB Output is correct
8 Correct 0 ms 2164 KB Output is correct
9 Correct 0 ms 2164 KB Output is correct
10 Correct 0 ms 2168 KB Output is correct
11 Correct 0 ms 2428 KB Output is correct
12 Correct 0 ms 2164 KB Output is correct
13 Correct 0 ms 2164 KB Output is correct
14 Correct 0 ms 2428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2032 KB Output is correct
2 Correct 0 ms 2032 KB Output is correct
3 Correct 0 ms 2032 KB Output is correct
4 Correct 0 ms 2032 KB Output is correct
5 Correct 0 ms 2032 KB Output is correct
6 Correct 0 ms 2032 KB Output is correct
7 Correct 0 ms 2032 KB Output is correct
8 Correct 0 ms 2032 KB Output is correct
9 Correct 0 ms 2032 KB Output is correct
10 Correct 0 ms 2032 KB Output is correct
11 Correct 0 ms 2032 KB Output is correct
12 Correct 0 ms 2032 KB Output is correct
13 Correct 0 ms 2032 KB Output is correct
14 Correct 0 ms 2032 KB Output is correct
15 Correct 0 ms 2032 KB Output is correct
16 Correct 0 ms 2032 KB Output is correct
17 Correct 0 ms 2032 KB Output is correct
18 Correct 0 ms 2032 KB Output is correct
19 Correct 0 ms 2032 KB Output is correct
20 Correct 0 ms 2032 KB Output is correct
21 Correct 0 ms 2032 KB Output is correct
22 Correct 0 ms 2032 KB Output is correct
23 Correct 0 ms 2032 KB Output is correct
24 Correct 0 ms 2032 KB Output is correct
25 Correct 0 ms 2164 KB Output is correct
26 Correct 0 ms 2032 KB Output is correct
27 Correct 0 ms 2164 KB Output is correct
28 Correct 0 ms 2164 KB Output is correct
29 Correct 0 ms 2032 KB Output is correct
30 Correct 0 ms 2164 KB Output is correct
31 Correct 0 ms 2032 KB Output is correct
32 Correct 0 ms 2164 KB Output is correct
33 Correct 0 ms 2164 KB Output is correct
34 Correct 0 ms 2168 KB Output is correct
35 Correct 0 ms 2428 KB Output is correct
36 Correct 0 ms 2164 KB Output is correct
37 Correct 0 ms 2164 KB Output is correct
38 Correct 0 ms 2428 KB Output is correct
39 Correct 0 ms 2032 KB Output is correct
40 Correct 0 ms 2168 KB Output is correct
41 Correct 0 ms 2168 KB Output is correct
42 Correct 0 ms 2032 KB Output is correct
43 Correct 0 ms 2164 KB Output is correct
44 Correct 0 ms 2164 KB Output is correct
45 Correct 0 ms 2032 KB Output is correct
46 Correct 0 ms 2164 KB Output is correct
47 Correct 0 ms 2164 KB Output is correct
48 Correct 0 ms 2164 KB Output is correct
49 Correct 0 ms 2164 KB Output is correct
50 Correct 0 ms 2164 KB Output is correct
51 Correct 0 ms 2300 KB Output is correct
52 Correct 0 ms 2432 KB Output is correct
53 Correct 0 ms 2428 KB Output is correct
54 Correct 0 ms 2428 KB Output is correct
55 Correct 3 ms 2428 KB Output is correct
56 Correct 0 ms 2428 KB Output is correct
57 Correct 0 ms 2164 KB Output is correct
58 Correct 0 ms 2164 KB Output is correct
59 Correct 0 ms 2300 KB Output is correct
60 Correct 0 ms 2032 KB Output is correct
61 Correct 0 ms 2164 KB Output is correct
62 Correct 0 ms 2164 KB Output is correct
63 Correct 0 ms 2164 KB Output is correct
64 Correct 0 ms 2168 KB Output is correct
65 Correct 0 ms 2164 KB Output is correct
66 Correct 0 ms 2032 KB Output is correct
67 Correct 0 ms 2164 KB Output is correct
68 Correct 0 ms 2164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2032 KB Output is correct
2 Correct 0 ms 2032 KB Output is correct
3 Correct 0 ms 2032 KB Output is correct
4 Correct 0 ms 2032 KB Output is correct
5 Correct 0 ms 2032 KB Output is correct
6 Correct 0 ms 2032 KB Output is correct
7 Correct 0 ms 2032 KB Output is correct
8 Correct 0 ms 2032 KB Output is correct
9 Correct 0 ms 2032 KB Output is correct
10 Correct 0 ms 2032 KB Output is correct
11 Correct 0 ms 2032 KB Output is correct
12 Correct 0 ms 2032 KB Output is correct
13 Correct 0 ms 2032 KB Output is correct
14 Correct 0 ms 2032 KB Output is correct
15 Correct 0 ms 2032 KB Output is correct
16 Correct 0 ms 2032 KB Output is correct
17 Correct 0 ms 2032 KB Output is correct
18 Correct 0 ms 2032 KB Output is correct
19 Correct 0 ms 2032 KB Output is correct
20 Correct 0 ms 2032 KB Output is correct
21 Correct 0 ms 2032 KB Output is correct
22 Correct 0 ms 2032 KB Output is correct
23 Correct 0 ms 2032 KB Output is correct
24 Correct 0 ms 2032 KB Output is correct
25 Correct 0 ms 2164 KB Output is correct
26 Correct 0 ms 2032 KB Output is correct
27 Correct 0 ms 2164 KB Output is correct
28 Correct 0 ms 2164 KB Output is correct
29 Correct 0 ms 2032 KB Output is correct
30 Correct 0 ms 2164 KB Output is correct
31 Correct 0 ms 2032 KB Output is correct
32 Correct 0 ms 2164 KB Output is correct
33 Correct 0 ms 2164 KB Output is correct
34 Correct 0 ms 2168 KB Output is correct
35 Correct 0 ms 2428 KB Output is correct
36 Correct 0 ms 2164 KB Output is correct
37 Correct 0 ms 2164 KB Output is correct
38 Correct 0 ms 2428 KB Output is correct
39 Correct 0 ms 2032 KB Output is correct
40 Correct 0 ms 2168 KB Output is correct
41 Correct 0 ms 2168 KB Output is correct
42 Correct 0 ms 2032 KB Output is correct
43 Correct 0 ms 2164 KB Output is correct
44 Correct 0 ms 2164 KB Output is correct
45 Correct 0 ms 2032 KB Output is correct
46 Correct 0 ms 2164 KB Output is correct
47 Correct 0 ms 2164 KB Output is correct
48 Correct 0 ms 2164 KB Output is correct
49 Correct 0 ms 2164 KB Output is correct
50 Correct 0 ms 2164 KB Output is correct
51 Correct 0 ms 2300 KB Output is correct
52 Correct 0 ms 2432 KB Output is correct
53 Correct 0 ms 2428 KB Output is correct
54 Correct 0 ms 2428 KB Output is correct
55 Correct 3 ms 2428 KB Output is correct
56 Correct 0 ms 2428 KB Output is correct
57 Correct 0 ms 2164 KB Output is correct
58 Correct 0 ms 2164 KB Output is correct
59 Correct 0 ms 2300 KB Output is correct
60 Correct 0 ms 2032 KB Output is correct
61 Correct 0 ms 2164 KB Output is correct
62 Correct 0 ms 2164 KB Output is correct
63 Correct 0 ms 2164 KB Output is correct
64 Correct 0 ms 2168 KB Output is correct
65 Correct 0 ms 2164 KB Output is correct
66 Correct 0 ms 2032 KB Output is correct
67 Correct 0 ms 2164 KB Output is correct
68 Correct 0 ms 2164 KB Output is correct
69 Correct 26 ms 4936 KB Output is correct
70 Correct 33 ms 5636 KB Output is correct
71 Correct 23 ms 4420 KB Output is correct
72 Correct 16 ms 3372 KB Output is correct
73 Correct 9 ms 2704 KB Output is correct
74 Correct 29 ms 5196 KB Output is correct
75 Correct 23 ms 4620 KB Output is correct
76 Correct 19 ms 4340 KB Output is correct
77 Correct 29 ms 4176 KB Output is correct
78 Correct 29 ms 4508 KB Output is correct
79 Correct 116 ms 26036 KB Output is correct
80 Correct 139 ms 23420 KB Output is correct
81 Correct 103 ms 25436 KB Output is correct
82 Correct 103 ms 17644 KB Output is correct
83 Correct 166 ms 36996 KB Output is correct
84 Correct 139 ms 36996 KB Output is correct
85 Correct 149 ms 36992 KB Output is correct
86 Correct 123 ms 36996 KB Output is correct
87 Correct 156 ms 12976 KB Output is correct
88 Correct 149 ms 15576 KB Output is correct
89 Correct 43 ms 9920 KB Output is correct
90 Correct 49 ms 6624 KB Output is correct
91 Correct 29 ms 4904 KB Output is correct
92 Correct 23 ms 3584 KB Output is correct
93 Correct 19 ms 3808 KB Output is correct
94 Correct 19 ms 3656 KB Output is correct
95 Correct 19 ms 3632 KB Output is correct
96 Correct 23 ms 3520 KB Output is correct
97 Correct 19 ms 4068 KB Output is correct
98 Correct 19 ms 4944 KB Output is correct