Submission #721807

#TimeUsernameProblemLanguageResultExecution timeMemory
721807rshohruhEvent Hopping (BOI22_events)C++14
0 / 100
1550 ms7176 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int N, Q; vector<pair<int, int>> events; vector<int> graph[MAXN]; vector<int> switches; int main() { cin >> N >> Q; events.resize(N + 1); for (int i = 1; i <= N; i++) { cin >> events[i].first >> events[i].second; } sort(events.begin() + 1, events.end()); for (int i = 1; i <= N; i++) { for (int j = i + 1; j <= N; j++) { if (events[j].first <= events[i].second) { graph[i].push_back(j); } else { break; } } } while (Q--) { int s, e; cin >> s >> e; switches.assign(N + 1, -1); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, s}); switches[s] = 0; while (!pq.empty()) { int u = pq.top().second; int w = pq.top().first; pq.pop(); if (u == e) { cout << switches[e] << endl; break; } for (int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if (switches[v] == -1 || switches[v] > switches[u] + 1) { switches[v] = switches[u] + 1; pq.push({switches[v], v}); } } } if (switches[e] == -1) { cout << "impossible" << endl; } } return 0; }

Compilation message (stderr)

events.cpp: In function 'int main()':
events.cpp:42:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for (int i = 0; i < graph[u].size(); i++) {
      |                             ~~^~~~~~~~~~~~~~~~~
events.cpp:36:17: warning: unused variable 'w' [-Wunused-variable]
   36 |             int w = pq.top().first;
      |                 ^
#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...