Submission #43579

#TimeUsernameProblemLanguageResultExecution timeMemory
43579RezwanArefin01Jakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
307 ms78924 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 30000; int n, m, b[maxn], p[maxn], dist[maxn]; set<int> st[maxn]; vector<int> adj[maxn], cost[maxn]; void addedge(int u, int v, int c) { adj[u].push_back(v); cost[u].push_back(c); } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif int ans = 0; scanf("%d %d", &n, &m); for(int i = 0; i < m; i++) { scanf("%d %d", &b[i], &p[i]); st[b[i]].insert(p[i]); } for(int pos = 0; pos < n; pos++) { for(int p : st[pos]) { for(int i = 1; ; i++) { int nxt = pos + i * p; if(nxt < n) { addedge(pos, nxt, i); if(st[nxt].find(p) != st[nxt].end()) break; } else break; } for(int i = 1; ; i++) { int nxt = pos - i * p; if(nxt >= 0) { addedge(pos, nxt, i); if(st[nxt].find(p) != st[nxt].end()) break; } else break; } } } priority_queue<ii, vector<ii>, greater<ii> > q; memset(dist, 63, sizeof dist); q.push({dist[b[0]] = 0, b[0]}); while(!q.empty()) { ii x = q.top(); q.pop(); int u = x.second, w = x.first; for(int i = 0; i < adj[u].size(); i++) { int v = adj[u][i], c = cost[u][i]; if(dist[v] > w + c) { dist[v] = w + c; q.push({dist[v], v}); } } } if(dist[b[1]] >= 1e8) puts("-1"); else cout << dist[b[1]] << endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main(int, const char**)':
skyscraper.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < adj[u].size(); i++) {
                    ^
skyscraper.cpp:22:6: warning: unused variable 'ans' [-Wunused-variable]
  int ans = 0;
      ^
skyscraper.cpp:23:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
skyscraper.cpp:26:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   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...