답안 #754092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754092 2023-06-06T16:55:19 Z jakobrs Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 403136 KB
#include <algorithm>
#include <iostream>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>

using i64 = int64_t;

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    i64 n, q;
    std::cin >> n >> q;

    struct Point {
        i64 time;
        int type;
        int idx;

        bool operator<(const Point &rhs) const {
            return std::tie(time, type, idx) <
                   std::tie(rhs.time, rhs.type, rhs.idx);
        }
    };

    std::vector<std::vector<i64>> nexts(n);
    std::unordered_set<i64> current;
    std::vector<Point> points;

    for (int i = 0; i < n; i++) {
        i64 s, e;
        std::cin >> s >> e;

        points.push_back(Point{.time = s, .type = 0, .idx = i});
        points.push_back(Point{.time = e, .type = 1, .idx = i});
        points.push_back(Point{.time = e, .type = 2, .idx = i});
    }

    std::sort(points.begin(), points.end());

    for (auto point : points) {
        switch (point.type) {
            case 0:
                current.insert(point.idx);
                break;
            case 1:
                nexts[point.idx].insert(nexts[point.idx].end(), current.begin(),
                                        current.end());
                break;
            case 2:
                current.erase(point.idx);
                break;
        }
    }

    std::vector<bool> visited(n);
    std::vector<i64> next;
    std::vector<i64> more;
    for (i64 i = 0; i < q; i++) {
        int s, e;
        std::cin >> s >> e;
        s--, e--;

        std::fill(visited.begin(), visited.end(), false);
        next.clear();
        more.clear();
        next.push_back(s);
        visited[s] = true;

        for (i64 time = 0; !next.empty(); time++) {
            for (i64 node : next) {
                if (node == e) {
                    std::cout << time << '\n';

                    goto next;
                }

                for (i64 possible : nexts[node]) {
                    if (!visited[possible]) {
                        visited[possible] = true;
                        more.push_back(possible);
                    }
                }
            }

            std::swap(next, more);
            more.clear();
        }

        std::cout << "impossible\n";
    next:;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1572 ms 10932 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 13 ms 3016 KB Output is correct
8 Correct 12 ms 4380 KB Output is correct
9 Correct 121 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 13 ms 3016 KB Output is correct
8 Correct 12 ms 4380 KB Output is correct
9 Correct 121 ms 8276 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 5 ms 1620 KB Output is correct
16 Correct 13 ms 3028 KB Output is correct
17 Correct 13 ms 4276 KB Output is correct
18 Correct 106 ms 8276 KB Output is correct
19 Execution timed out 1586 ms 44556 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 13 ms 3016 KB Output is correct
8 Correct 12 ms 4380 KB Output is correct
9 Correct 121 ms 8276 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 2 ms 424 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 15 ms 1612 KB Output is correct
16 Correct 14 ms 3052 KB Output is correct
17 Correct 19 ms 4384 KB Output is correct
18 Correct 105 ms 8280 KB Output is correct
19 Correct 370 ms 12852 KB Output is correct
20 Correct 186 ms 14768 KB Output is correct
21 Execution timed out 1596 ms 403136 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1556 ms 12916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1572 ms 10932 KB Time limit exceeded
3 Halted 0 ms 0 KB -