Submission #1097790

#TimeUsernameProblemLanguageResultExecution timeMemory
1097790KasymKJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
328 ms13768 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 3e4+5; const ll INF = 1e18; set<int> adj[N]; ll dis[N]; int main(){ int n, m, s, t; scanf("%d%d", &n, &m); for(int i = 1; i <= m; ++i){ int x, p; scanf("%d%d", &x, &p), x++; if(i == 1) s = x; if(i == 2) t = x; adj[x].insert(p); } for(int i = 1; i <= n; ++i) dis[i] = INF; priority_queue<pli, vector<pli>, greater<pli>> pq; pq.push({0, s}); dis[s] = 0; while(!pq.empty()){ pli P = pq.top(); pq.pop(); ll val = P.ff; int x = P.ss; if(dis[x] != val) continue; for(int p : adj[x]){ for(int i = 1; x-i*p >= 1; ++i){ int to = x-i*p; if(umin(dis[to], val+i)) pq.push({dis[to], to}); } for(int i = 1; x+i*p <= n; ++i){ int to = x+i*p; if(umin(dis[to], val+i)) pq.push({dis[to], to}); } } } int d = -1; printf("%lld\n", dis[t]==INF?d:dis[t]); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d%d", &x, &p), x++;
      |         ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:36:12: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |     dis[s] = 0;
      |     ~~~~~~~^~~
skyscraper.cpp:58:27: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     printf("%lld\n", dis[t]==INF?d:dis[t]);
      |                      ~~~~~^
#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...