Submission #1077830

#TimeUsernameProblemLanguageResultExecution timeMemory
1077830dostsJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
30 ms4820 KiB
//DOST SEFEROĞLU #include <bits/stdc++.h> #pragma GCC optimise("O3,unroll-loops") using namespace std; #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> dis(n, LLONG_MAX); vector<set<int>> p(n); priority_queue<pii> q; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; p[x].insert(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 (auto j : p[x]) { for (int i = x + j; i < n; i += j) { if (!p[i].empty() && d + abs(i - x) / j < dis[i]) { dis[i] = d + abs(i - x) / j; q.push({-dis[i], i}); } if (p[i].find(j) != p[i].end()) break; } for (int i = x - j; i >= 0; i -= j) { if (!p[i].empty() && d + abs(i - x) / j < dis[i]) { dis[i] = d + abs(i - x) / j; q.push({-dis[i], i}); } if (p[i].find(j) != p[i].end()) break; } } } cout << (dis[tx] == LLONG_MAX ? -1 : dis[tx]); }

Compilation message (stderr)

skyscraper.cpp:3: warning: ignoring '#pragma GCC optimise' [-Wunknown-pragmas]
    3 | #pragma GCC optimise("O3,unroll-loops")
      | 
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:58:20: warning: 'tx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     cout << (dis[tx] == LLONG_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...