Submission #322373

#TimeUsernameProblemLanguageResultExecution timeMemory
322373minoumJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1094 ms1772 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int MAXN = 3e4 + 1, inf = 1e5; int n, m, b[2], d[MAXN], sz = 0, mn, u; bool wasmn[MAXN]; vector <int> ps[MAXN]; /* inline void dij(){ for(int i = 0; i < n; i++) d[i] = inf; d[b[0]] = 0; for(int h = 0; h < n; h++){ mn = inf, u = -1; for(int i = 0; i < n; i++) if(!wasmn[i] && d[i] < mn) mn = d[i], u = i; wasmn[u] = true; if(u == b[1] || d[u] >= inf) return; for(int k: ps[u]){ for(int i = u % k; i < n; i += k) if(d[i] > d[u] + (abs(u - i) / k)) d[i] = d[u] + (abs(u - i) / k); } } return; } */ int main() { // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // cin >> n >> m; scanf("%d", &n); scanf("%d", &m); int bb, pp; for(int i = 0; i < m; i++){ // cin >> bb >> pp; scanf("%d", &bb); scanf("%d", &pp); ps[bb].push_back({pp}); if(i == 0) b[0] = bb; if(i == 1) b[1] = bb; } // dij(); for(int i = 0; i < n; i++) d[i] = inf; d[b[0]] = 0; for(int h = 0; h < n; h++){ mn = inf, u = -1; for(int i = 0; i < n; i++) if(!wasmn[i] && d[i] < mn) mn = d[i], u = i; wasmn[u] = true; if(u == b[1] || d[u] >= inf) break; for(int k: ps[u]){ for(int i = u % k; i < n; i += k) if(d[i] > d[u] + (abs(u - i) / k)) d[i] = d[u] + (abs(u - i) / k); } } // 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:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%d", &n); scanf("%d", &m);
      |  ~~~~~^~~~~~~~~~
skyscraper.cpp:34:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%d", &n); scanf("%d", &m);
      |                   ~~~~~^~~~~~~~~~
skyscraper.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |   scanf("%d", &bb); scanf("%d", &pp);
      |   ~~~~~^~~~~~~~~~~
skyscraper.cpp:38:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |   scanf("%d", &bb); scanf("%d", &pp);
      |                     ~~~~~^~~~~~~~~~~
#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...