Submission #106233

#TimeUsernameProblemLanguageResultExecution timeMemory
106233HideoJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1086 ms45200 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mk make_pair #define fr first #define sc second #define vi vector < int > #define vl vector < ll > #define pi pair < int, int > #define pii pair < int, pi > #define vii vector < pi > const int N = 2e5 + 7; const int INF = 1e9 + 7; int l[N], p[N], d[N]; int n, m, ans; vii g[N]; priority_queue < pi > pq; main(){ ans = INF; cin >> n >> m; for (int i = 1; i <= m; i++){ d[i] = INF; scanf("%d%d", &l[i], &p[i]); } pq.push(mk(0, 1)); while (!pq.empty()){ int v = pq.top().sc, c = -pq.top().fr; pq.pop(); if (c >= ans) break; if (c >= d[v]) continue; if (v == 2){ ans = c; continue; } if (d[v] == INF){ for (int j = 1; j <= m; j++) if (v != j && l[v] % p[v] == l[j] % p[v]) g[v].pb(mk(j, abs(l[j] - l[v]) / p[v])); } d[v] = c; for (pi to : g[v]){ if (d[to.fr] > d[v] + to.sc) pq.push(mk(-d[v] - to.sc, to.fr)); } } if (ans == INF) cout << -1; else cout << ans; }

Compilation message (stderr)

skyscraper.cpp:25:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &l[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...