Submission #1120161

#TimeUsernameProblemLanguageResultExecution timeMemory
1120161vjudge1Event Hopping (BOI22_events)C++17
0 / 100
1587 ms10296 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second typedef long long ll; vector<ll> g[200100]; ll d[200100]; bool ok(pair<ll, pair<ll, ll>> a, pair<ll, pair<ll, ll>> b) { return (b.s.f <= a.f); } void solve() { ll n; cin>>n; ll Q; cin>>Q; vector<pair<ll, pair<ll, ll>>> v; for(ll i=1; i<=n; i++) { ll l,r; cin>>l>>r; v.push_back({r, {l, i}}); } sort(v.begin(), v.end()); for(ll i=0; i<v.size(); i++) { for(ll j=i+1; j<v.size(); j++) { if(ok(v[i], v[j])) { g[v[i].s.s].push_back(v[j].s.s); } } } while(Q--) { ll x,y; cin>>x>>y; queue<ll> q; for(ll i=1; i<=n; i++) d[i]=1e18; d[x]=0; q.push(x); while(!q.empty()) { ll v=q.front(); q.pop(); for(auto to: g[v]) { if(d[to] > d[v]+1) { d[to]=d[v]+1; q.push(to); } } } if(d[y] == 1e18) cout<<"impossible\n"; else cout<<d[y]<<'\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--) { solve(); cout<<'\n'; } } /* 5 5 2 3 1 2 7 9 4 7 4 6 2 1 5 2 5 4 4 5 5 3 */

Compilation message (stderr)

events.cpp: In function 'void solve()':
events.cpp:20:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(ll i=0; i<v.size(); i++) {
      |                 ~^~~~~~~~~
events.cpp:21:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(ll j=i+1; j<v.size(); j++) {
      |                       ~^~~~~~~~~
#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...