Submission #357687

# Submission time Handle Problem Language Result Execution time Memory
357687 2021-01-24T12:48:09 Z koioi.org-ckyun6724 None (KOI16_laser) C++17
100 / 100
262 ms 36076 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int mx = 1005;

namespace geo{
    struct pt{
        ll x, y;
        int i, c;
        pt() {}
        pt(ll x, ll y):x(x),y(y) {}
        pt(ll x, ll y, int i, int c):x(x),y(y),i(i),c(c) {}
        bool operator< (pt z){
            return x==z.x?y<z.y:x<z.x;
        }
        bool operator== (pt z){
            return x==z.x && y==z.y;
        }
        ll operator* (pt z){
            return x * z.y - y * z.x;
        }
        pt operator- (pt z){
            return pt(x - z.x, y - z.y);
        }
    };
    int ccw(pt u, pt v, pt w){
        ll T = (v-u)*(w-u);
        return T?T>0?1:-1:0;
    }

    ll d(pt u, pt v){
        return (u.x-v.x)*(u.x-v.x) + (u.y-v.y)*(u.y-v.y);
    }

    void andrew(vector<pt>& ch, pt* s, pt* e){
        if(s==e){
            ch.resize(1);
            ch.push_back(*s);
            return;
        }
        sort(s,e+1);
        vector<pt> uh, dh;
        for(pt *t = s; t != (e+1); t++){
            for(int c; ( c=uh.size() ) > 1 && ccw(uh[c-2],uh[c-1],*t) <= 0; uh.pop_back());
            uh.push_back(*t);
        }
        for(pt *t = e; t != (s-1); t--){
            for(int c; ( c=dh.size() ) > 1 && ccw(dh[c-2],dh[c-1],*t) <= 0; dh.pop_back());
            dh.push_back(*t);
        }
        ch.resize(uh.size()+dh.size()-2);
        copy( uh.begin(), uh.end(), ch.begin() );
        copy( dh.begin()+1, dh.end()-1, ch.begin() + uh.size() );
    }
}
using namespace geo;

int n;
pii match[mx];
pt tam[mx * 3], tmp[mx * 3];

void dnc(pt* s, pt* e){
    if(s >= e) return;
    vector<pt> ch;
    andrew(ch,s,e);
    int id=0;
    for(; id<ch.size(); id++){
        if(ch[id].c == 2) break;
    }
    if(id == ch.size()){
        pt *t;
        sort(s+1,e+1,[s](pt &u, pt &v){return ccw(*s,u,v) > 0;});
        int score = 0;
        pt *u = nullptr;
        for(t = s; t != (e+1); t++){
            score += t->c;
            if(score == 0){
                u = t;
                break;
            }
            if(score == -1 && t != s){
                swap(*s, *t);
                u = t - 1;
                break;
            }
        }
        dnc(s,u);
        dnc(u+1,e);
    }
    else{
        pt *t;
        for(t = s; t != (e+1); t++){
            if(*t == ch[id]) break;
        }
        swap(*s,*t);
        sort(s+1,e+1,[s](pt &u, pt &v){return ccw(*s,u,v) > 0;});
        int score = 0;
        pt *u = nullptr, *v = nullptr;
        for(t = s; t != (e+1); t++){
            score += t -> c;
            if(score == 1 && !u) u = t;
            if(score == 0 && u && !v){
                v = t;
                break;
            }
        }
        match[s->i] = {u->i,v->i};
        dnc(s+1,u-1);
        dnc(u+1,v-1);
        dnc(v+1,e);
    }
}

void init(){
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tam[i].x >> tam[i].y;
        tam[i].i = i;
        tam[i].c = 2;
        match[i] = {-1,-1};
    }
    for(int i=n; i<3*n; i++){
        cin >> tam[i].x >> tam[i].y;
        tam[i].i = i - n + 1;
        tam[i].c = -1;
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    init();
    dnc(tam,tam+3*n-1);
    for(int i=0; i<n; i++){
        cout << match[i].first << ' ' << match[i].second << '\n';
    }
}

Compilation message

laser.cpp: In function 'void dnc(geo::pt*, geo::pt*)':
laser.cpp:69:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<geo::pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(; id<ch.size(); id++){
      |           ~~^~~~~~~~~~
laser.cpp:72:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<geo::pt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     if(id == ch.size()){
      |        ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
37 Correct 2 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 2 ms 748 KB Output is correct
50 Correct 2 ms 748 KB Output is correct
51 Correct 2 ms 748 KB Output is correct
52 Correct 2 ms 748 KB Output is correct
53 Correct 2 ms 748 KB Output is correct
54 Correct 2 ms 748 KB Output is correct
55 Correct 2 ms 748 KB Output is correct
56 Correct 2 ms 748 KB Output is correct
57 Correct 2 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 3 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 2 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
37 Correct 2 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 2 ms 748 KB Output is correct
50 Correct 2 ms 748 KB Output is correct
51 Correct 2 ms 748 KB Output is correct
52 Correct 2 ms 748 KB Output is correct
53 Correct 2 ms 748 KB Output is correct
54 Correct 2 ms 748 KB Output is correct
55 Correct 2 ms 748 KB Output is correct
56 Correct 2 ms 748 KB Output is correct
57 Correct 2 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 3 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 2 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 21 ms 492 KB Output is correct
70 Correct 22 ms 552 KB Output is correct
71 Correct 20 ms 640 KB Output is correct
72 Correct 13 ms 492 KB Output is correct
73 Correct 13 ms 492 KB Output is correct
74 Correct 18 ms 492 KB Output is correct
75 Correct 22 ms 492 KB Output is correct
76 Correct 27 ms 620 KB Output is correct
77 Correct 42 ms 748 KB Output is correct
78 Correct 24 ms 620 KB Output is correct
79 Correct 201 ms 35948 KB Output is correct
80 Correct 199 ms 35908 KB Output is correct
81 Correct 197 ms 35948 KB Output is correct
82 Correct 198 ms 35948 KB Output is correct
83 Correct 229 ms 35948 KB Output is correct
84 Correct 200 ms 35820 KB Output is correct
85 Correct 221 ms 36076 KB Output is correct
86 Correct 202 ms 35820 KB Output is correct
87 Correct 258 ms 1260 KB Output is correct
88 Correct 262 ms 1388 KB Output is correct
89 Correct 261 ms 1132 KB Output is correct
90 Correct 261 ms 1132 KB Output is correct
91 Correct 40 ms 620 KB Output is correct
92 Correct 41 ms 620 KB Output is correct
93 Correct 33 ms 620 KB Output is correct
94 Correct 19 ms 620 KB Output is correct
95 Correct 20 ms 620 KB Output is correct
96 Correct 20 ms 620 KB Output is correct
97 Correct 23 ms 620 KB Output is correct
98 Correct 20 ms 620 KB Output is correct