Submission #857635

#TimeUsernameProblemLanguageResultExecution timeMemory
85763512345678Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
15 ms16472 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e3+5; int n, m, st, ed, jp, b, p[nx], dp[nx][nx]; vector<int> v[nx]; priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> q; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>st>>p[0]>>ed>>p[1]; v[ed].push_back(1); for (int i=1; i<m-1; i++) cin>>b>>p[i+1], v[b].push_back(i+1); for (int i=0; i<nx; i++) for (int j=0; j<nx; j++) dp[i][j]=INT_MAX; dp[p[0]][st]=0; q.push({0, p[0], st}); while (!q.empty()) { auto [w, c, l]=q.top(); //cout<<c<<' '<<w<<' '<<l<<'\n'; q.pop(); if (l+c<n&&w+1<dp[c][l+c]) dp[c][l+c]=w+1, q.push({w+1, c, l+c}); if (l-c>=0&&w+1<dp[c][l-c]) dp[c][l-c]=w+1, q.push({w+1, c, l-c}); for (auto nw:v[l]) { if (nw==1) { cout<<w; return 0; } if (w<dp[p[nw]][l]) dp[p[nw]][l]=w, q.push({w, p[nw], l}); } } cout<<-1; }
#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...