제출 #163665

#제출 시각아이디문제언어결과실행 시간메모리
163665MinnakhmetovJakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
402 ms184780 KiB
#include <bits/stdc++.h> #define ll long long #define all(aaa) aaa.begin(), aaa.end() using namespace std; struct E { int to, w; }; const int N = 3e4 + 5, P = 200, V = N + N + N * P, INF = 1e9; vector<E> g[V]; int d[V]; signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[m + x].push_back({i, 0}); if (y < P) { g[i].push_back({n + m + x * P + y, 0}); } else { int z = x - y, w = 1; while (z >= 0) { g[i].push_back({m + z, w}); z -= y; w++; } z = x + y, w = 1; while (z < n) { g[i].push_back({m + z, w}); z += y; w++; } } } for (int i = 0; i < n; i++) { for (int j = 1; j < P; j++) { int ver = n + m + i * P + j; g[ver].push_back({m + i, 0}); if (i - j >= 0) { g[ver].push_back({ver - j * P, 1}); } if (i + j < n) { g[ver].push_back({ver + j * P, 1}); } } } fill(d, d + V, INF); d[0] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; q.push({d[0], 0}); while (!q.empty()) { int node = q.top().second, cd = q.top().first; q.pop(); if (cd != d[node]) continue; for (E e : g[node]) { if (d[e.to] > cd + e.w) { d[e.to] = cd + e.w; q.push({d[e.to], e.to}); } } } cout << (d[1] < INF ? d[1] : -1); 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...