Submission #1110702

#TimeUsernameProblemLanguageResultExecution timeMemory
1110702vjudge1Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
272 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) template <class X, class Y> bool minimize(X &x, Y y) { if (x > y) return x = y, true; else return false; } int n, m; const ll INF = (ll) 1e18 + 7; #define ii pair <long long, int> #define MAX 50'005 vector <ii> adj[MAX + 2]; int b[MAX + 2], p[MAX + 2]; ll dist[MAX + 2]; vector <int> jump[MAX + 2]; void Dijkstra(int s) { priority_queue <ii, vector <ii>, greater <ii>> q; FOR(i, 1, n) dist[i] = INF; dist[s] = 0; q.push({0, s}); while (!q.empty()) { ll cost = q.top().first; int u = q.top().second; q.pop(); if (cost > dist[u]) continue; for (auto it : adj[u]) { int v = it.first, w = it.second; if (minimize(dist[v], dist[u] + w)) { q.push({dist[v], v}); } } } cout << (dist[b[2]] != INF ? dist[b[2]] : -1); } void add_edge(int u, int v, int w) { adj[u].push_back({v, w}); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); #define task "sky" if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> m; FOR(i, 1, m) { cin >> b[i] >> p[i]; ++b[i]; jump[b[i]].push_back(p[i]); } FOR(i, 1, n) { for (int x : jump[i]) { int j = x + i, cur = 1; while (j <= n) { add_edge(i, j, cur); j += x; ++cur; } j = i - x, cur = 1; while (j >= 1) { add_edge(i, j, cur); j -= x; ++cur; } } } Dijkstra(b[1]); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...