Submission #589027

# Submission time Handle Problem Language Result Execution time Memory
589027 2022-07-04T08:54:31 Z 1zaid1 Event Hopping (BOI22_events) C++14
10 / 100
1500 ms 2800 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

const int M = 1e4+2;
struct rng {int l, r, i;};
int dist[M];

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int n, p;
    cin >> n >> p;

    vector<rng> v(n);
    for (auto &[l, r, i]:v) cin >> l >> r;
    for (int i = 0; i < n; i++) v[i].i = i;

    bitset<100005> vis;
    while (p--) {
        int a, b;
        cin >> a >> b; a--; b--;
        if (a == b) {
            cout << 0 << endl;
            continue;
        }

        vis[a] = 1;
        queue<rng> q;
        q.push(v[a]);
        while (!q.empty()) {
            // cout << q << "I: "<< cr.i+1 << endl;
            rng t = q.front(); q.pop();
            for (auto [l, r, i]:v) {
                if (!vis[i]) {
                    if (l <= t.r && t.r <= r) {
                        vis[i] = 1;
                        dist[i] = dist[t.i]+1;
                        q.push({l, r, i});
                    }
                }
            }
        }

        if (vis[b]) {
            cout << dist[b] << endl;
        } else {
            cout << "impossible" << endl;
        } vis = 0;

        for (int i = 0; i <= n; i++) dist[i] = 0;
    }

    return 0;
}
/*
8 5
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
1 7
2 4
3 3
5 8

5 2
1 3
2 4
4 7
7 9
3 7
1 4
3 2
*/

Compilation message

events.cpp: In function 'int main()':
events.cpp:16:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |     for (auto &[l, r, i]:v) cin >> l >> r;
      |                ^
events.cpp:34:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |             for (auto [l, r, i]:v) {
      |                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 27 ms 2800 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 184 ms 340 KB Output is correct
4 Correct 41 ms 344 KB Output is correct
5 Correct 70 ms 344 KB Output is correct
6 Correct 77 ms 340 KB Output is correct
7 Correct 172 ms 372 KB Output is correct
8 Correct 178 ms 376 KB Output is correct
9 Correct 168 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 184 ms 340 KB Output is correct
4 Correct 41 ms 344 KB Output is correct
5 Correct 70 ms 344 KB Output is correct
6 Correct 77 ms 340 KB Output is correct
7 Correct 172 ms 372 KB Output is correct
8 Correct 178 ms 376 KB Output is correct
9 Correct 168 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 203 ms 348 KB Output is correct
13 Correct 51 ms 344 KB Output is correct
14 Correct 79 ms 340 KB Output is correct
15 Correct 82 ms 340 KB Output is correct
16 Correct 173 ms 348 KB Output is correct
17 Correct 157 ms 352 KB Output is correct
18 Correct 212 ms 352 KB Output is correct
19 Execution timed out 1578 ms 440 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 184 ms 340 KB Output is correct
4 Correct 41 ms 344 KB Output is correct
5 Correct 70 ms 344 KB Output is correct
6 Correct 77 ms 340 KB Output is correct
7 Correct 172 ms 372 KB Output is correct
8 Correct 178 ms 376 KB Output is correct
9 Correct 168 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 184 ms 340 KB Output is correct
13 Correct 83 ms 340 KB Output is correct
14 Correct 82 ms 340 KB Output is correct
15 Correct 76 ms 352 KB Output is correct
16 Correct 220 ms 348 KB Output is correct
17 Correct 153 ms 352 KB Output is correct
18 Correct 157 ms 352 KB Output is correct
19 Runtime error 23 ms 2800 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 2764 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 27 ms 2800 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -