Submission #997536

#TimeUsernameProblemLanguageResultExecution timeMemory
997536AbitoPassport (JOI23_passport)C++17
0 / 100
224 ms103384 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt #define int long long #define ll long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=2505; int dis[N][N],L[N],R[N],n,q; pair<int,int> par[N][N]; void bfs(int s){ for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) dis[i][j]=INT_MAX; dis[L[s]][R[s]]=1;par[L[s]][R[s]]={s,s}; queue<pair<int,int>> q; q.push({L[s],R[s]}); while (!q.empty()){ int l=q.front().F,r=q.front().S; q.pop(); for (int i=l;i<par[l][r].F;i++){ int l1=min(l,L[i]),r1=max(r,R[i]); if (dis[l1][r1]!=INT_MAX) continue; dis[l1][r1]=dis[l][r]+1; par[l1][r1]={l,r}; q.push({l1,r1}); } for (int i=r;i>par[l][r].S;i--){ int l1=min(l,L[i]),r1=max(r,R[i]); if (dis[l1][r1]!=INT_MAX) continue; dis[l1][r1]=dis[l][r]+1; par[l1][r1]={l,r}; q.push({l1,r1}); } }return; } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n; for (int i=1;i<=n;i++) cin>>L[i]>>R[i]; cin>>q; while (q--){ int x;cin>>x; bfs(x); if (dis[1][n]==INT_MAX) cout<<-1<<endl; else cout<<dis[1][n]<<endl; } 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...