Submission #124135

#TimeUsernameProblemLanguageResultExecution timeMemory
124135AyaBenSaadJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
468 ms49348 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 3; //number of skyscrapers const int M = 3e4 + 4; //number of doges; const int inf = 1e9; int n, m, b[M], p[M], ok; vector <pair <int, int> > adj[M]; int dis[N][N], vis[N]; void Dijkstra (int u) { priority_queue <pair <long long, int> > q; vis[u]++; q.push ({-1, u}); while (q.size()) { int x = q.top().second; q.pop(); for (auto e : adj[x]) { int v = e.first; long long c = e.second; if ((!vis[v]) || vis [v] > c + vis[x]){ vis[v] = c + vis[x]; q.push({-vis[v], v}); } } } } int main () { scanf ("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &b[i], &p[i]); for (int j = 0; j < n; j++) { if (abs(j-b[i]) % p[i] == 0) { if (dis[b[i]][j] == 0 || dis[b[i]][j] > abs(j-b[i]) / p[i]) dis[b[i]][j] = abs(j-b[i]) / p[i]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ( dis[i][j]) adj[i].push_back({j, dis[i][j]}); } } Dijkstra(b[0]); if (vis[b[1]]) printf("%d\n", vis[b[1]]-1); else puts("-1"); }

Compilation message (stderr)

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