Submission #109587

#TimeUsernameProblemLanguageResultExecution timeMemory
109587arman_ferdousJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
6 ms3200 KiB
#include <bits/stdc++.h> using namespace std; const int N = 30010; const int oo = 1e9; using ii = pair<int,int>; int n, m; vector<int> f[N]; map<int,int> has[N]; int dist[N]; vector<ii> g[N]; priority_queue<ii, vector<ii>, greater<ii> > q; int main() { scanf("%d %d", &n, &m); for(int i = 0; i < m; i++) { int b, p; scanf("%d %d", &b, &p); f[b].push_back(p); } for(int i = 0; i < n; i++) { sort(f[i].begin(), f[i].end()); f[i].erase(unique(f[i].begin(),f[i].end()), f[i].end()); for(int p : f[i]) has[i][p] = 1; } for(int i = 0; i < n; i++) { for(int p : f[i]) { for(int x = i + p, c = 1; x < n; x += p, c++) { g[i].push_back({c, x}); if(has[x][p]) break; } for(int x = i - p, c = 1; x >= 0; x -= p, c++) { g[i].push_back({c, x}); if(has[x][p]) break; } } } for(int i = 0; i < n; i++) dist[i] = oo; q.push({0,0}); dist[0] = 0; while(!q.empty()) { auto U = q.top(); q.pop(); int cw = U.first, u = U.second; for(auto e : g[u]) { if(dist[e.second] > cw + e.first) { dist[e.second] = cw + e.first; q.push({cw + e.first, e.second}); } } } if(dist[1] == oo) puts("-1"); else printf("%d\n", dist[1]); return 0; }

Compilation message (stderr)

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