Submission #928114

#TimeUsernameProblemLanguageResultExecution timeMemory
928114OAleksaJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
2 ms2164 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define int long long const int N = 30069; const int inf = 1e18; int n, m, a[N], b[N], dis[N];; vector<int> c[N]; vector<pair<int, int>> g[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n >> m; for (int i = 1;i <= m;i++) { cin >> a[i] >> b[i], ++a[i]; c[a[i]].push_back(i); } for (int i = 1;i <= n;i++) dis[i] = inf; priority_queue<pair<int, int>> q; q.push({0, 1}); dis[a[1]] = 0; while (!q.empty()) { auto i = q.top().s; auto w = abs(q.top().f); q.pop(); if (i == 2) break; for (int j = a[i], d = 0;j <= n;j += b[i],d++) { if (dis[j] > w + d && !c[j].empty()) { dis[j] = w + d; for (auto u : c[j]) q.push({-dis[j], u}); } } for (int j = a[i], d = 0;j >= 1;j -= b[i],d++) { if (dis[j] > w + d && !c[j].empty()) { dis[j] = w + d; for (auto u : c[j]) q.push({-dis[j], u}); } } } if (dis[a[2]] == inf) cout << -1 << '\n'; else cout << dis[a[2]] << '\n'; } return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   23 |    for (int i = 1;i <= n;i++)
      |    ^~~
skyscraper.cpp:25:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   25 |   priority_queue<pair<int, int>> q;
      |   ^~~~~~~~~~~~~~
#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...