Submission #589020

#TimeUsernameProblemLanguageResultExecution timeMemory
589020shayanebrahimiEvent Hopping (BOI22_events)C++14
10 / 100
1577 ms60856 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' #define fast_io; ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); const ll MOD=1e9+7;//998244353//1e9+9//1111211111; //ll tavmd(ll a,ll b){if(b==0){return 1;}if(b%2==0){ll x=tavmd(a,b/2);return(x*x)%MOD;}else{return(a%MOD*tavmd(a,b-1)%MOD)%MOD;}} const ll MAXN=2e5+10; const ll INF=8e18; const ll LOG=30; ll s[MAXN],e[MAXN],n,q,d[MAXN]; vector<ll>adj[MAXN]; int main(){ fast_io; fill(d,d+MAXN,INF); cin>>n>>q; for(int i=1;i<=n;i++){ cin>>s[i]>>e[i]; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i!=j&&e[i]>=s[j]&&e[i]<=e[j]){ adj[i].push_back(j); } } } while(q--){ fill(d,d+MAXN,INF); ll u,v; cin>>u>>v; d[u]=0; queue<ll>pq; pq.push(u); while(!pq.empty()){ ll x=pq.front(); pq.pop(); for(auto i:adj[x]){ if(d[i]==INF){ d[i]=d[x]+1; pq.push(i); } } } if(d[v]==INF) cout<<"impossible"<<endl; else cout<<d[v]<<endl; } return 0; }

Compilation message (stderr)

events.cpp:5:9: warning: ISO C++11 requires whitespace after the macro name
    5 | #define fast_io;                 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(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...