Submission #838680

# Submission time Handle Problem Language Result Execution time Memory
838680 2023-08-27T15:04:58 Z skittles1412 Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 3012 KB
#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

void solve() {
    int n, q;
    cin >> n >> q;

    vector<pair<int, int>> arr(n);
    for (auto& [l, r] : arr) {
        cin >> l >> r;
    }

    while (q--) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;

        if (u == v) {
            cout << 0 << endl;
            continue;
        }

        int ql = arr[v].first, qr = arr[v].second, ans = 0;

        while (ql > arr[u].second) {
            int n_opt = 1e9;

            for (auto& [l, r] : arr) {
                if (ql <= r && r <= qr) {
                    n_opt = min(n_opt, l);
                }
            }

            if (n_opt >= ql) {
                break;
            }
            ans++;
            ql = n_opt;
        }

        if (ql <= arr[u].second && arr[u].second <= qr) {
            ans++;
            cout << ans << endl;
        } else {
            cout << "impossible" << endl;
        }
    }
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1568 ms 1108 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 138 ms 312 KB Output is correct
4 Correct 14 ms 336 KB Output is correct
5 Correct 26 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 138 ms 312 KB Output is correct
4 Correct 14 ms 336 KB Output is correct
5 Correct 26 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 145 ms 340 KB Output is correct
13 Correct 14 ms 340 KB Output is correct
14 Correct 25 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Execution timed out 1560 ms 472 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 138 ms 312 KB Output is correct
4 Correct 14 ms 336 KB Output is correct
5 Correct 26 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 136 ms 340 KB Output is correct
13 Correct 14 ms 356 KB Output is correct
14 Correct 25 ms 212 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Execution timed out 1560 ms 3012 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1572 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1568 ms 1108 KB Time limit exceeded
3 Halted 0 ms 0 KB -