Submission #977520

#TimeUsernameProblemLanguageResultExecution timeMemory
977520AmaarsaaJakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
5 ms1368 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long ; ll D[30005]; vector < ll > v[30005]; int main() { // freopen("moocast.in", "r", stdin); // freopen("moocast.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(NULL); ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j; cin >> m >> n; priority_queue < pair < ll, ll >, vector < pair < ll, ll >> , greater < pair < ll, ll >> > pq; ll a[n + 2], b[n + 2]; for (i = 0; i < n; i ++) { cin >> a[i] >> b[i]; v[a[i]].push_back(b[i]); } for (i = 1; i <= m; i ++) D[i] = 1e18; D[a[0]] = 0; pq.push({0, a[0]}); while(!pq.empty()) { x = pq.top().first; y = pq.top().second; pq.pop(); if ( x != D[y]) continue; for ( ll X : v[y]) { s = y - X; dist = 1; while ( s >= 0) { if ( D[s] > D[y] + dist) { D[s] = D[y] + dist; pq.push({D[s], s}); } dist ++; s -= X; } s = y + X; dist = 1; while ( s < m) { if ( D[s] > D[y] + dist) { D[s] = D[y] + dist; pq.push({D[s], s}); } dist ++; s += X; } } } if ( D[a[1]] == 1e18) cout << -1 << endl; else cout << D[a[1]] << endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:12:5: warning: unused variable 't' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |     ^
skyscraper.cpp:12:14: warning: unused variable 'ans' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |              ^~~
skyscraper.cpp:12:22: warning: unused variable 'sum' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                      ^~~
skyscraper.cpp:12:38: warning: unused variable 'r' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                                      ^
skyscraper.cpp:12:41: warning: unused variable 'p' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                                         ^
skyscraper.cpp:12:47: warning: unused variable 'j' [-Wunused-variable]
   12 |  ll t, n, m, ans, s, sum,dist, x, y, r, p, i, j;
      |                                               ^
#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...