Submission #1037689

#TimeUsernameProblemLanguageResultExecution timeMemory
1037689stdfloatBali Sculptures (APIO15_sculpture)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define ff first #define ss second #define pii pair<int, int> int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; int tx; vector<int> p(n), dis(n, INT_MAX); priority_queue<pii> q; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; p[x] = y; if (!i) { dis[x] = 0; q.push({0, x}); } else if (i == 1) tx = x; } while (!q.empty()) { auto [d, x] = q.top(); d = -d; q.pop(); if (d != dis[x]) continue; for (int i = x; i < n; i += p[x]) { if (p[i] && d + abs(i - x) / p[x] < dis[i]) { dis[i] = d + abs(i - x) / p[x]; q.push({-dis[i], i}); } } for (int i = x; i >= 0; i -= p[x]) { if (p[i] && d + abs(i - x) / p[x] < dis[i]) { dis[i] = d + abs(i - x) / p[x]; q.push({-dis[i], i}); } } } cout << (dis[tx] == INT_MAX ? -1 : dis[tx]); }

Compilation message (stderr)

sculpture.cpp: In function 'int32_t main()':
sculpture.cpp:53:20: warning: 'tx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |     cout << (dis[tx] == INT_MAX ? -1 : dis[tx]);
      |                    ^
#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...