Submission #928247

#TimeUsernameProblemLanguageResultExecution timeMemory
928247Darren0724Passport (JOI23_passport)C++17
16 / 100
1519 ms1031244 KiB
#include <bits/stdc++.h> using namespace std; #define LCBorz ios_base::sync_with_stdio(false); cin.tie(0); #define all(x) x.begin(), x.end() #define endl '\n' const int N=305; const int INF=1e9; inline int id(int a,int b){ return a*N+b; } int32_t main() { LCBorz; int n;cin>>n; vector<int> adj[N*N],dis(N*N,INF); vector<int> b(N),c(N); for(int i=1;i<=n;i++){ cin>>b[i]>>c[i]; for(int j=1;j<=i;j++){ for(int k=i;k<=n;k++){ adj[id(j,k)].push_back(id(min(b[i],j),max(c[i],k))); //cout<<id(j,k)<<' '<<id(min(b[i],j),max(c[i],k))<<endl; } } } int q1;cin>>q1; int p;cin>>p; queue<int> q; q.push(id(b[p],c[p])); dis[id(b[p],c[p])]=1; while(q.size()){ int p=q.front(); q.pop(); for(int j:adj[p]){ if(dis[j]==INF){ dis[j]=dis[p]+1; q.push(j); } } } int ans=dis[id(1,n)]; cout<<(ans==INF?-1:ans)<<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...