# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
38424 |
2018-01-04T05:45:15 Z |
kajebiii |
None (KOI16_laser) |
C++14 |
|
206 ms |
65536 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;});
vector<PT> cv; vector<int> index;
for(int i=0; i<n; i++) {
while(SZ(cv) >= 2 && cv[SZ(cv)-2].ccw(cv.back(), ps[i]) <= 0) cv.pop_back(), index.pop_back();
cv.push_back(ps[i]); index.push_back(i);
}
int cix = -1;
for(int i=0; i<SZ(cv); i++) if(cv[i].c == 2) {cix = index[i]; 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:83: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);
^
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
0 ms |
2296 KB |
Output is correct |
3 |
Correct |
0 ms |
2296 KB |
Output is correct |
4 |
Correct |
0 ms |
2164 KB |
Output is correct |
5 |
Correct |
0 ms |
2164 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 |
2164 KB |
Output is correct |
11 |
Correct |
3 ms |
2828 KB |
Output is correct |
12 |
Correct |
0 ms |
2404 KB |
Output is correct |
13 |
Correct |
3 ms |
2828 KB |
Output is correct |
14 |
Correct |
3 ms |
2828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
2428 KB |
Output is correct |
26 |
Correct |
0 ms |
2296 KB |
Output is correct |
27 |
Correct |
0 ms |
2296 KB |
Output is correct |
28 |
Correct |
0 ms |
2164 KB |
Output is correct |
29 |
Correct |
0 ms |
2164 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 |
2164 KB |
Output is correct |
35 |
Correct |
3 ms |
2828 KB |
Output is correct |
36 |
Correct |
0 ms |
2404 KB |
Output is correct |
37 |
Correct |
3 ms |
2828 KB |
Output is correct |
38 |
Correct |
3 ms |
2828 KB |
Output is correct |
39 |
Correct |
0 ms |
2032 KB |
Output is correct |
40 |
Correct |
0 ms |
2164 KB |
Output is correct |
41 |
Correct |
0 ms |
2164 KB |
Output is correct |
42 |
Correct |
0 ms |
2164 KB |
Output is correct |
43 |
Correct |
0 ms |
2168 KB |
Output is correct |
44 |
Correct |
0 ms |
2032 KB |
Output is correct |
45 |
Correct |
0 ms |
2164 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 |
2168 KB |
Output is correct |
49 |
Correct |
6 ms |
2828 KB |
Output is correct |
50 |
Correct |
0 ms |
2828 KB |
Output is correct |
51 |
Correct |
0 ms |
2828 KB |
Output is correct |
52 |
Correct |
3 ms |
2828 KB |
Output is correct |
53 |
Correct |
3 ms |
2828 KB |
Output is correct |
54 |
Correct |
0 ms |
2828 KB |
Output is correct |
55 |
Correct |
3 ms |
2828 KB |
Output is correct |
56 |
Correct |
3 ms |
2828 KB |
Output is correct |
57 |
Correct |
0 ms |
2032 KB |
Output is correct |
58 |
Correct |
3 ms |
2428 KB |
Output is correct |
59 |
Correct |
0 ms |
2164 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 |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
2428 KB |
Output is correct |
26 |
Correct |
0 ms |
2296 KB |
Output is correct |
27 |
Correct |
0 ms |
2296 KB |
Output is correct |
28 |
Correct |
0 ms |
2164 KB |
Output is correct |
29 |
Correct |
0 ms |
2164 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 |
2164 KB |
Output is correct |
35 |
Correct |
3 ms |
2828 KB |
Output is correct |
36 |
Correct |
0 ms |
2404 KB |
Output is correct |
37 |
Correct |
3 ms |
2828 KB |
Output is correct |
38 |
Correct |
3 ms |
2828 KB |
Output is correct |
39 |
Correct |
0 ms |
2032 KB |
Output is correct |
40 |
Correct |
0 ms |
2164 KB |
Output is correct |
41 |
Correct |
0 ms |
2164 KB |
Output is correct |
42 |
Correct |
0 ms |
2164 KB |
Output is correct |
43 |
Correct |
0 ms |
2168 KB |
Output is correct |
44 |
Correct |
0 ms |
2032 KB |
Output is correct |
45 |
Correct |
0 ms |
2164 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 |
2168 KB |
Output is correct |
49 |
Correct |
6 ms |
2828 KB |
Output is correct |
50 |
Correct |
0 ms |
2828 KB |
Output is correct |
51 |
Correct |
0 ms |
2828 KB |
Output is correct |
52 |
Correct |
3 ms |
2828 KB |
Output is correct |
53 |
Correct |
3 ms |
2828 KB |
Output is correct |
54 |
Correct |
0 ms |
2828 KB |
Output is correct |
55 |
Correct |
3 ms |
2828 KB |
Output is correct |
56 |
Correct |
3 ms |
2828 KB |
Output is correct |
57 |
Correct |
0 ms |
2032 KB |
Output is correct |
58 |
Correct |
3 ms |
2428 KB |
Output is correct |
59 |
Correct |
0 ms |
2164 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 |
3956 KB |
Output is correct |
70 |
Correct |
29 ms |
4544 KB |
Output is correct |
71 |
Correct |
26 ms |
3172 KB |
Output is correct |
72 |
Correct |
23 ms |
3316 KB |
Output is correct |
73 |
Correct |
16 ms |
2736 KB |
Output is correct |
74 |
Correct |
53 ms |
6664 KB |
Output is correct |
75 |
Correct |
33 ms |
4104 KB |
Output is correct |
76 |
Correct |
56 ms |
6088 KB |
Output is correct |
77 |
Correct |
36 ms |
4084 KB |
Output is correct |
78 |
Correct |
19 ms |
3304 KB |
Output is correct |
79 |
Memory limit exceeded |
206 ms |
65536 KB |
Memory limit exceeded |
80 |
Halted |
0 ms |
0 KB |
- |