제출 #108267

#제출 시각아이디문제언어결과실행 시간메모리
108267maksim_gaponovJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1076 ms3576 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define pb push_back const int INF = 1e18; bool cmin(int &a, const int &b) { if (a > b) { a = b; return 1; } return 0; } void run() { int n, m; cin >> n >> m; vector<int> b(m), p(m); vector<vector<int>> who(n); for (int i = 0; i < m; ++i) { cin >> b[i] >> p[i]; who[b[i]].pb(i); } vector<int> dist(n, INF); queue<int> q; q.push(b[0]); dist[b[0]] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (auto x : who[u]) { int cnt = 0; for (int i = u; i < n; i += p[x]) { if (cmin(dist[i], dist[u] + cnt)) { q.push(i); } ++cnt; } cnt = 0; for (int i = u; i >= 0; i -= p[x]) { if (cmin(dist[i], dist[u] + cnt)) { q.push(i); } ++cnt; } } } if (dist[b[1]] >= INF) dist[b[1]] = -1; cout << dist[b[1]] << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); run(); }
#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...