Submission #122436

#TimeUsernameProblemLanguageResultExecution timeMemory
122436IOrtroiiiJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
160 ms75984 KiB
#include <bits/stdc++.h> using namespace std; const int N = 30030; const int MG = 200; const int inf = 1e9; int d[N]; int b[N], p[N]; bool was[N][MG]; bool useless[N]; vector<pair<int, int>> g[N]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; ++i) { scanf("%d %d", b + i, p + i); if (p[i] < MG) { if (was[b[i]][p[i]]) { useless[i] = true; } else { was[b[i]][p[i]] = true; } } } for (int i = 0; i < m; ++i) { if (useless[i]) continue; for (int j = 1; ; ++j) { int v = b[i] - j * p[i]; if (v < 0) break; g[b[i]].emplace_back(v, j); if (p[i] < MG && was[v][p[i]]) { break; } } for (int j = 1; ; ++j) { int v = b[i] + j * p[i]; if (v >= n) break; g[b[i]].emplace_back(v, j); if (p[i] < MG && was[v][p[i]]) { break; } } } for (int i = 0; i < n; ++i) { d[i] = inf; } priority_queue<pair<int, int>> q; d[b[0]] = 0; q.emplace(0, b[0]); while (!q.empty()) { int du, u; tie(du, u) = q.top(); q.pop(); du = -du; if (d[u] != du) { continue; } for (auto e : g[u]) { int v, w; tie(v, w) = e; if (d[v] > d[u] + w) { d[v] = d[u] + w; q.emplace(-d[v], v); } } } printf("%d\n", (d[b[1]] == inf ? -1 : d[b[1]])); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:9: 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:12: 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...