Submission #45916

#TimeUsernameProblemLanguageResultExecution timeMemory
45916TalantJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
900 ms17596 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define OK puts("OK"); #define pb push_back #define mk make_pair #define int long long using namespace std; typedef long long ll; const int inf = (int)1e15 + 7; const int N = (int)2e5 + 7; int n,m; int b[N],p[N]; int d[N]; vector <int> vec[N]; vector <pair<int,int> > g[N]; priority_queue<pair<int,int> > q; bool check (int l,int r,int x) { if (abs(r - l) % x == 0) return true; return false; } int f (int l,int r,int x) { return (abs(r - l) / x); } main () { scanf ("%lld%lld", &n,&m); for (int i = 1; i <= m; i ++) { scanf ("%lld%lld", &b[i],&p[i]); b[i] ++; vec[b[i]].pb(p[i]); } for (int i = 1; i <= n; i ++) { sort (vec[i].begin(),vec[i].end()); vec[i].erase(unique(vec[i].begin(),vec[i].end()),vec[i].end()); } for (int i = 1; i <= n; i ++) d[i] = inf; d[b[1]] = 0; q.push({0,b[1]}); while (!q.empty()) { int v = q.top().sc,cur = -q.top().fr; q.pop(); if (cur > d[v]) continue; if (b[2] == v) { printf("%lld\n", d[v]); return 0; } for (auto to : vec[v]) { for (int i = 1; to * i + v <= n; i ++) { if (d[v] + i < d[to * i + v]) { d[to * i + v] = d[v] + i; q.push({-d[to * i + v],to * i + v}); } } for (int i = 1; to * i <= v; i ++) { if (d[v] + i < d[v - to * i]) { d[v - to * i] = d[v] + i; q.push({-d[v - to * i],v - to * i}); } } } } if (d[b[2]] == inf) puts("-1"); else printf("%lld\n", d[b[2]]); }

Compilation message (stderr)

skyscraper.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:34:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf ("%lld%lld", &n,&m);
       ~~~~~~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp:37:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf ("%lld%lld", &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...