Submission #1037848

#TimeUsernameProblemLanguageResultExecution timeMemory
1037848KasymKJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
12 ms604 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 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 MOD = 1e9+7; // const int INF = 1e9; const int N = 2e3+5; const ll INF = (ll)1e18; int n, m; int b[N], p[N]; ll dist[N]; priority_queue<pair<ll, int>> pq; ll solve(){ for(int i = 0; i < m; ++i) dist[i] = INF; dist[0] = 0; pq.push({0, 0}); while (!pq.empty()){ auto x = pq.top(); pq.pop(); if (-x.ff > dist[x.ss]) continue; if (x.ss == 1) return -x.ff; for(int i = 0; i < m; ++i) if (abs(b[x.ss]-b[i])%p[x.ss] == 0){ int w = abs(b[x.ss] - b[i])/p[x.ss]; if (dist[i] > dist[x.ss]+w){ dist[i] = dist[x.ss]+w; pq.push({-dist[i], i}); } } } return -1; } int main(){ scanf("%d%d", &n, &m); for(int i = 0; i < m; ++i) scanf("%d%d", &b[i], &p[i]); ll answer = solve(); printf("%lld\n", answer); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d%d", &b[i], &p[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...