Submission #599135

#TimeUsernameProblemLanguageResultExecution timeMemory
599135VanillaEvent Hopping (BOI22_events)C++17
10 / 100
1586 ms199472 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int maxn = 5e3 + 2; struct nd { int x; int y; int idx; bool operator < (const nd& oth) const { return make_pair(x, y) < make_pair(oth.x, oth.y); } } a [maxn]; int dist [maxn][maxn]; vector <int> ad [maxn]; void prec (int u, int x) { set <int> q; // queue <int> q; q.insert(u); dist[u][x] = 0; while (!q.empty()) { int u = *q.begin(); q.erase(q.begin()); for (int v: ad[u]){ if (dist[u][x] + 1 < dist[v][x]) { dist[v][x] = dist[u][x] + 1; q.insert(v); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,q; cin >> n >> q; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++) dist[i][j] = 1e9; cin >> a[i].x >> a[i].y; a[i].idx = i; } cout << "\n"; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (i != j && a[j].x <= a[i].y && a[i].y <= a[j].y) { // cout << i << " " << j << "\n"; ad[i].push_back(j); } } } // sort(a, a + n); for (int i = 0; i < n; i++){ prec(i, i); } // for (int i = 0; i < n; i++){ // for (int j = 0; j < n; j++){ // cout << i << " " << j << " " << dist[j][i] << "\n"; // } // } while (q--){ int x,y; cin >> x >> y; x--, y--; cout << (dist[y][x] == 1e9 ? "impossible": to_string(dist[y][x])) << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...