답안 #544122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544122 2022-04-01T05:26:11 Z tengiz05 Roads (CEOI20_roads) C++17
100 / 100
150 ms 10616 KB
#include <bits/stdc++.h>

using i64 = long long;
using ld = long double;

struct Point {
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
};
bool operator<(const Point &a, const Point &b) {
    return std::pair(a.x, a.y) < std::pair(b.x, b.y);
}

constexpr int N = 1E5 + 5, inf = 1E8;

Point left[N], right[N];
int Time;

struct Segment {
    int i;
    mutable Point f;
    Segment(int i) : i(i) {}
};
ld pos(const Segment &a) {
    int i = a.i;
    if (Time == left[i].x)
        return left[i].y;
    ld ratio = ld(right[i].y - left[i].y) / (right[i].x - left[i].x);
    return left[i].y + ratio * (Time - left[i].x);
}
bool operator<(const Segment &a, const Segment &b) {
    return pos(a) < pos(b);
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<std::pair<Point, int>> events;
    
    for (int i = 0; i < n; i++) {
        std::cin >> left[i].x >> left[i].y >> right[i].x >> right[i].y;
        if (right[i] < left[i]) {
            std::swap(left[i], right[i]);
        }
        events.emplace_back(left[i], i + 1);
        events.emplace_back(right[i], -(i + 1));
    }
    
    left[n] = {-inf, -inf};
    right[n] = {inf, -inf};
    left[n + 1] = {-inf, inf};
    right[n + 1] = {inf, inf};
    Time = -inf;
    
    std::set<Segment> s;
    s.insert(Segment(n));
    s.insert(Segment(n + 1));
    
    s.begin()->f = {-inf, -inf};
    
    std::sort(events.begin(), events.end());
    
    for (auto [p, v] : events) {
        int i = std::abs(v) - 1;
        Time = p.x;
        if (v > 0) {
            s.insert(Segment(i));
            auto it = s.find(Segment(i));
            it->f = p;
            auto a = std::prev(it)->f;
            std::prev(it)->f = p;
            
            if (a.x != -inf) {
                std::cout << a.x << " " << a.y << " " << p.x << " " << p.y << "\n";
            }
        } else {
            auto it = s.find(Segment(i));
            std::prev(it)->f = p;
            s.erase(it);
        }
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 52 ms 4752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1888 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 11 ms 2752 KB Output is correct
5 Correct 20 ms 3652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 2 ms 1896 KB Output is correct
4 Correct 10 ms 2744 KB Output is correct
5 Correct 21 ms 3588 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 2 ms 1896 KB Output is correct
9 Correct 12 ms 2768 KB Output is correct
10 Correct 150 ms 10132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 12 ms 2768 KB Output is correct
5 Correct 20 ms 3572 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 3 ms 1896 KB Output is correct
9 Correct 11 ms 2724 KB Output is correct
10 Correct 49 ms 6036 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1888 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 13 ms 2756 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1888 KB Output is correct
8 Correct 2 ms 1904 KB Output is correct
9 Correct 12 ms 2788 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 11 ms 2896 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 2 ms 1888 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 6 ms 2156 KB Output is correct
23 Correct 6 ms 2268 KB Output is correct
24 Correct 11 ms 2496 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 52 ms 4748 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 2 ms 2004 KB Output is correct
6 Correct 13 ms 2856 KB Output is correct
7 Correct 20 ms 3544 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 2 ms 2004 KB Output is correct
11 Correct 11 ms 2748 KB Output is correct
12 Correct 149 ms 10236 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 10 ms 2768 KB Output is correct
17 Correct 50 ms 6008 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1888 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 1892 KB Output is correct
23 Correct 2 ms 1892 KB Output is correct
24 Correct 2 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 6 ms 2260 KB Output is correct
27 Correct 6 ms 2260 KB Output is correct
28 Correct 11 ms 2472 KB Output is correct
29 Correct 80 ms 7032 KB Output is correct
30 Correct 110 ms 10064 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 99 ms 7772 KB Output is correct
33 Correct 102 ms 7748 KB Output is correct
34 Correct 127 ms 9780 KB Output is correct
35 Correct 130 ms 10100 KB Output is correct
36 Correct 130 ms 10616 KB Output is correct