Submission #330581

#TimeUsernameProblemLanguageResultExecution timeMemory
330581minoumJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1087 ms3432 KiB
#include<bits/stdc++.h> ///#pragma GCC optimization ("unroll-loops") using namespace std; typedef long long int ll; const int MAXN = 3e4+1, inf = INT_MAX / 2; int n, m, b[MAXN], p[MAXN], d[MAXN], tmp; vector <int> ps[MAXN]; priority_queue <pair<int,int>> q; int main() { // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // cin >> n >> m; scanf("%d", &n); scanf("%d", &m); for(int i = 0; i < m; i++){ // cin >> bb >> pp; scanf("%d", b+i); scanf("%d", p+i); ps[b[i]].push_back({p[i]}); } for(int i = 0; i < n; i++) d[i] = inf; d[b[0]] = 0; q.push({0, b[0]}); while(!q.empty()){ int u = q.top().second, dd = -q.top().second; q.pop(); if(d[u] < dd) continue; // if(u == b[1] || d[u] >= inf) break; for(int k: ps[u]){ /*for(int i = u % k; i < n; i += k){ tmp = abs(u - i); if(d[i] > d[u] + (tmp / k)){ d[i] = d[u] + (tmp / k); q.push({-d[i], i}); } }*/ for(int i = u % k; i < u; i += k) if(d[i] > d[u] + (u - i) / k){ d[i] = d[u] + (u - i) / k; q.push({-d[i], i}); } for(int i = u + k; i < n; i += k) if(d[i] > d[u] + (i - u) / k){ d[i] = d[u] + (i - u) / k; q.push({-d[i], i}); } } } // cout << ((d[b[1]] >= inf)?-1:d[b[1]]); if(d[b[1]] >= inf) printf("%d", -1); else printf("%d", d[b[1]]); return 0; }

Compilation message (stderr)

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