답안 #644775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644775 2022-09-25T08:24:29 Z FedShat Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 3640 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll INFLL = numeric_limits<ll>::max() / 2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
#endif
    int n, q;
    cin >> n >> q;
    vector<pair<int, int>> lr(n);
    for (int i = 0; i < n; ++i) {
        cin >> lr[i].first >> lr[i].second;
    }
    auto can = [&](int i, int j) {// i -> j
        auto [li, ri] = lr[i];
        auto [lj, rj] = lr[j];
        return lj <= ri && ri <= rj;
    };
    vector<int> prv(n);
    for (int i = 0; i < n; ++i) {
        int ind = -1;
        for (int j = 0; j < n; ++j) {
            if (can(j, i) && i != j) {
                if (ind == -1 || lr[j].first < lr[ind].first) {
                    ind = j;
                }
            }
        }
        prv[i] = ind;
    }
    while (q--) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        int ans = 0;
        while (!can(a, b)) {
            if (prv[b] == -1) {
                ans = -1;
                break;
            }
            b = prv[b];
            ++ans;
        }
        if (a != b && ans != -1) {
            ++ans;
        }
        if (ans == -1) {
            cout << "impossible\n";
        } else {
            cout << ans << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Execution timed out 1579 ms 3640 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Execution timed out 1592 ms 340 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Execution timed out 1592 ms 340 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Execution timed out 1592 ms 340 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1559 ms 3536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Execution timed out 1579 ms 3640 KB Time limit exceeded
3 Halted 0 ms 0 KB -