Submission #789387

#TimeUsernameProblemLanguageResultExecution timeMemory
789387ThMinh_Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1083 ms33264 KiB
#include<bits/stdc++.h> #define forin(i, a, b) for(int i = a; i <= b; ++i) #define ii pair<int, int> using namespace std; const int N = 3e4 + 10; int n, m; int b[N], p[N], d[N]; vector<ii> adj[N]; void dijkstra(int s) { priority_queue<ii, vector<ii>, greater<ii> > pq; fill(d + 1, d + m + 1, 1e9); pq.push({0, s}); d[s] = 0; while(!pq.empty()) { int kc, u; tie(kc, u) = pq.top(); pq.pop(); if(kc != d[u]) continue; for(auto e : adj[u]) { int w, v; tie(w, v) = e; if(d[v] <= d[u] + w) continue; d[v] = d[u] + w; pq.push({d[v], v}); } } } int main () { cin.tie(0)->sync_with_stdio(0); if(fopen("Task.inp","r")) { freopen("Task.inp","r",stdin); freopen("WA.out","w",stdout); } cin>>n>>m; forin(i, 1, m) cin>>b[i]>>p[i]; forin(i, 1, m) forin(j, 1, m) if(i != j) { bool ok = ((b[j] - b[i]) % p[i] == 0); if(ok) { int w = abs(b[j] - b[i]) / p[i]; adj[i].push_back({w, j}); } } dijkstra(1); if(d[2] == 1e9) cout<<-1; else cout<<d[2]; }

Compilation message (stderr)

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