Submission #738086

# Submission time Handle Problem Language Result Execution time Memory
738086 2023-05-08T07:06:16 Z DAleksa Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 3464 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5010;
vector<int> g[N];
int n, q;
int l[N], r[N];
int dist[N];
bool mark[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    for(int i = 0; i < n; i++) cin >> l[i] >> r[i];
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(l[j] <= r[i] && r[i] <= r[j]) g[i].push_back(j);
    while(q--) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        for(int i = 0; i < n; i++) {
            dist[i] = 1e9;
            mark[i] = false;
        }
        dist[x] = 0;
        queue<int> q;
        q.push(x);
        while(!q.empty()) {
            int u = q.front();
            q.pop();
            mark[u] = true;
            for(int v : g[u]) {
                if(mark[v]) continue;
                q.push(v);
                dist[v] = min(dist[v], dist[u] + 1);
            }
        }
        if(dist[y] == 1e9) cout << "impossible\n";
        else cout << dist[y] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 10 ms 1236 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 468 KB Output is correct
4 Correct 7 ms 480 KB Output is correct
5 Correct 6 ms 480 KB Output is correct
6 Correct 297 ms 1364 KB Output is correct
7 Execution timed out 1569 ms 3464 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 468 KB Output is correct
4 Correct 7 ms 480 KB Output is correct
5 Correct 6 ms 480 KB Output is correct
6 Correct 297 ms 1364 KB Output is correct
7 Execution timed out 1569 ms 3464 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 468 KB Output is correct
4 Correct 7 ms 480 KB Output is correct
5 Correct 6 ms 480 KB Output is correct
6 Correct 297 ms 1364 KB Output is correct
7 Execution timed out 1569 ms 3464 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1236 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 10 ms 1236 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -