Submission #870612

#TimeUsernameProblemLanguageResultExecution timeMemory
870612anha3k25cvpJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
131 ms65708 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define dl double #define st first #define nd second #define II pair <int, int> using namespace std; const int N = 5 + 1e5; const int inf = 7 + 1e9; int n, m; vector <int> b, p; namespace subtask5 { void main() { vector <set <int>> g(n); for (int i = 1; i <= m; i ++) g[b[i]].insert(p[i]); vector <vector <II>> adj(n); for (int i = 0; i < n; i ++) for (int val : g[i]) { for (int j = 1; j * val <= i; j ++) { adj[i].push_back({i - j * val, j}); if (g[i - j * val].count(val)) break; } for (int j = 1; i + j * val < n; j ++) { adj[i].push_back({i + j * val, j}); if (g[i + j * val].count(val)) break; } } vector <int> f(n, inf); priority_queue <II> q; q.push({-(f[b[1]] = 0), b[1]}); while (!q.empty()) { int du = -q.top().st, u = q.top().nd; q.pop(); if (f[u] < du) continue; if (u == b[2]) { cout << du; return; } for (auto z : adj[u]) { int v = z.st, w = z.nd; if (du + w < f[v]) q.push({-(f[v] = du + w), v}); } } cout << -1; } } int main() { #define TASKNAME "" ios_base :: sync_with_stdio (0); cin.tie (0); if ( fopen( TASKNAME".inp", "r" ) ) { freopen (TASKNAME".inp", "r", stdin); freopen (TASKNAME".out", "w", stdout); } cin >> n >> m; b.assign(m + 1, 0); p.assign(m + 1, 0); for (int i = 1; i <= m; i ++) cin >> b[i] >> p[i]; subtask5 :: main(); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:63:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:64:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen (TASKNAME".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...