Submission #644775

#TimeUsernameProblemLanguageResultExecution timeMemory
644775FedShatEvent Hopping (BOI22_events)C++17
0 / 100
1592 ms3640 KiB
#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"; } } }
#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...