제출 #398367

#제출 시각아이디문제언어결과실행 시간메모리
398367kylych03Jakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1022 ms3116 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; int d[30300][2]; vector<int> v[30300]; int p[30300]; int e[30303]; int main() { int n,m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> d[i][0] >> d[i][1]; int x = d[i][0]; int y = d[i][1]; v[x].push_back(y); } priority_queue<pair<int,int>> q; for (int i = 0; i < 30300; i++) e[i] = 1e9; q.push({0,d[0][0]}); e[d[0][0]] = 0; while(!q.empty()) { int s = q.top().s; int x = -q.top().f; q.pop(); if (x > e[s]) continue; if (s == d[1][0]) { cout << x << "\n"; return 0; } for (int u : v[s]) { int it = 1; for (int i = s-u; i >= 0; i -= u) { if (e[s] + it < e[i]) { // cout << s << " -> " << i << " " << it <<"\n"; e[i] = it + e[s]; q.push({-e[i],i}); } ++it; } it = 1; for (int i = s+u; i < n; i += u) { if (e[s] + it < e[i]) { // cout << s << " -> " << i << " " << it << "\n"; e[i] = it + e[s]; q.push({-e[i],i}); } ++it; } } } 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...