답안 #998765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998765 2024-06-14T16:31:58 Z Trustfulcomic Roads (CEOI20_roads) C++14
100 / 100
277 ms 12116 KB
#include<bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
#define x first
#define y second

struct Usecka{
    pii a,b;
    int idx;
};

bool stejny(Usecka a, Usecka b){
    if ((a.a.x == b.a.x && a.a.y == b.a.y && a.b.x == b.b.x && a.b.y == b.b.y) || (a.a.x == b.b.x && a.a.y == b.b.y && a.b.x == b.a.x && a.b.y == b.a.y)){
        return true;
    }
    return false;
}

bool comp(const Usecka& l, const Usecka& r){
    if ((l.a.x == r.a.x && l.a.y == r.a.y && l.b.x == r.b.x && l.b.y == r.b.y) || (l.a.x == r.b.x && l.a.y == r.b.y && l.b.x == r.a.x && l.b.y == r.a.y)){
        return false;
    }
    bool prohozeny = false;
    Usecka u;
    pii b;
    if (min(l.a.x,l.b.x) >= min(r.a.x,r.b.x) && min(l.a.x,l.b.x) <= max(r.a.x,r.b.x)){
        b = min(l.a, l.b);
        u = r;
    } else {
        b = min(r.a, r.b);
        u = l;
        prohozeny = true;
    }

    if (u.a.x == u.b.x || b.x == u.a.x){
        return prohozeny^(u.a.y>b.y);
    } else {
        long double ynko = u.a.y + ((long double)(u.b.y-u.a.y)*(b.x-u.a.x))/((long double)(u.b.x-u.a.x));
        return prohozeny^(ynko>b.y);
    }

}

int main(){
    int n; cin >> n;
    vector<Usecka> points(2*n);
    for (int i = 0; i<n; i++){
        int a,b,c,d; cin >> a >> b >> c >> d;
        points[2*i] = {{a,b},{c,d},i};
        points[2*i+1] = {{c,d},{a,b},i};
    }

    sort(points.begin(), points.end(), [](const Usecka& l, const Usecka &r){
        return (l.a.x < r.a.x) || (l.a.x == r.a.x && l.a.y < r.a.y);
    });

    vector<pii> nad(n, {INT_MAX,INT_MAX});
    vector<pii> pod(n, {INT_MAX,INT_MAX});

    pii last_deleted = {INT_MAX,INT_MAX};

    set<Usecka, decltype(&comp)> usecky(&comp);
    usecky.insert(points[0]);
    nad[points[0].idx] = points[0].a;
    pod[points[0].idx] = points[0].a;
    for (int i = 1; i<2*n; i++){
        auto it = usecky.lower_bound(points[i]);
        if (it != usecky.end() && stejny(*it, points[i])){
            if (it != usecky.begin()){
                it--;
                nad[it->idx] = points[i].a;
                it++;
            }
            it++;
            if (it != usecky.end()){
                pod[it->idx] = points[i].a;
            }
            it--;
            last_deleted = points[i].a;
            usecky.erase(it);
        } else {
            if (usecky.size() == 0){
                cout << points[i].a.x << " " << points[i].a.y << " " << last_deleted.x << " " << last_deleted.y << endl;
            } else {
                if (it != usecky.end()){
                    cout << points[i].a.x << " " << points[i].a.y << " " << pod[it->idx].x << " " << pod[it->idx].y << endl;
                } else {
                    it--;
                    cout << points[i].a.x << " " << points[i].a.y << " " << nad[it->idx].x << " " << nad[it->idx].y << endl;
                    it++;
                }
            }

            if (it != usecky.end()){
                pod[it->idx] = points[i].a;
            }
            if (it != usecky.begin()){
                it--;
                nad[it->idx] = points[i].a;
                it++;
            }
            nad[points[i].idx]=points[i].a;
            pod[points[i].idx]=points[i].a;
            usecky.insert(points[i]);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 121 ms 3316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 21 ms 1092 KB Output is correct
5 Correct 76 ms 2096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 26 ms 1092 KB Output is correct
5 Correct 44 ms 2128 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 23 ms 1580 KB Output is correct
10 Correct 268 ms 11752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 25 ms 1116 KB Output is correct
5 Correct 44 ms 2032 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 22 ms 1372 KB Output is correct
10 Correct 116 ms 5976 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 22 ms 1084 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 23 ms 1484 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 25 ms 1360 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 10 ms 604 KB Output is correct
23 Correct 9 ms 604 KB Output is correct
24 Correct 19 ms 1140 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 95 ms 3156 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 22 ms 1372 KB Output is correct
7 Correct 46 ms 2644 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 23 ms 1372 KB Output is correct
12 Correct 277 ms 11620 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 22 ms 1544 KB Output is correct
17 Correct 112 ms 5972 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 9 ms 604 KB Output is correct
27 Correct 9 ms 600 KB Output is correct
28 Correct 18 ms 1116 KB Output is correct
29 Correct 157 ms 7504 KB Output is correct
30 Correct 239 ms 11092 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 180 ms 8272 KB Output is correct
33 Correct 179 ms 8276 KB Output is correct
34 Correct 238 ms 10832 KB Output is correct
35 Correct 250 ms 11092 KB Output is correct
36 Correct 276 ms 12116 KB Output is correct