Submission #928093

#TimeUsernameProblemLanguageResultExecution timeMemory
928093OAleksaJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms1116 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second const int N = 30069; const int inf = 1e9; int n, m, a[N], b[N], dis[N];; vector<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]; g[a[i]].push_back(i); } for (int i = 1;i <= m;i++) dis[i] = inf; vector<int> dogos; dogos.push_back(1); dis[a[1]] = 0; while (!dogos.empty()) { auto v = dogos.back(); dogos.pop_back(); for (int i = a[v], j = dis[a[v]];i <= n;i += b[v],j++) { if (dis[i] > j) { dis[i] = j; for (auto u : g[i]) dogos.push_back(u); } } for (int i = a[v], j = dis[a[v]];i >= 1;i -= b[v],j++) { if (dis[i] > j) { dis[i] = j; for (auto u : g[i]) dogos.push_back(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:21:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   21 |    for (int i = 1;i <= m;i++)
      |    ^~~
skyscraper.cpp:23:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   23 |   vector<int> dogos;
      |   ^~~~~~
#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...