제출 #786168

#제출 시각아이디문제언어결과실행 시간메모리
786168devariaotaJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms596 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define keish ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; const int mod = 1e9 + 7; int n, m; signed main(){ keish; cin >> n >> m; vector<int> b(m), p(m); vector<vector<int>> e(n); for(int i = 0; i < n; i++){ cin >> b[i] >> p[i]; e[b[i]].push_back(p[i]); } vector<vector<int>> dis(n, vector<int>(2005)); queue<pair<int, int>> q; for(auto x : e[b[0]]){ dis[b[0]][x] = 0; q.push({b[0], x}); } while(!q.empty()){ auto [u, d] = q.front(); q.pop(); if(u == b[1]){ cout << dis[u][d] << '\n'; return 0; } if(u + d < n){ if(dis[u + d][d] != -1){ dis[u + d][d] = dis[u][d] + 1; q.push({u + d, d}); } for(auto v : e[u + d]){ if(dis[u + d][v] != -1){ dis[u + d][v] = dis[u][d] + 1; q.push({u + d, v}); } } } if(u - d >= 0){ if(dis[u - d][d] != -1){ dis[u - d][d] = dis[u][d] + 1; q.push({u - d, d}); } for(auto v : e[u - d]){ if(dis[u - d][v] != -1){ dis[u - d][v] = dis[u][d] + 1; q.push({u - d, v}); } } } } cout << -1 << '\n'; }
#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...