Submission #207090

#TimeUsernameProblemLanguageResultExecution timeMemory
207090Sa1loumJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
22 ms23832 KiB
#include <bits/stdc++.h> using namespace std; #define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mem(a,b) memset(a, b, sizeof(a)) #define F first #define S second #define Si size() #define pb(x) push_back(x) typedef double D; typedef long long ll; typedef long double ld; const int MOD=(int)1e9+7,MAX=(int)1e6+10; ll n,m,b[MAX],p[MAX],vis[MAX]; vector <pair<ll,ll> > v[MAX]; int main() { scanf("%lld%lld",&n,&m); for (int i=0;i<m;i++) { scanf("%lld%lld",&b[i],&p[i]); ll d=0; for (int j=b[i],k=b[i];;j+=p[i],k-=p[i]) { bool flag=0; if (0<=j && j<n) { flag=1; if (j!=b[i]) { v[b[i]].push_back({j,d}); } } if (0<=k && k<n) { flag=1; if (k!=b[i]) { v[b[i]].push_back({k,d}); } } d++; if (!flag) break; } } priority_queue <pair<ll,ll>> pq; pq.push({0,0}); while (!pq.empty()) { ll x=pq.top().S; ll w=-pq.top().F; pq.pop(); if (vis[x]) continue; vis[x]=1; if (x==1) {printf("%lld\n",w); return 0;} for (auto it:v[x]) { if (vis[it.F]) continue; pq.push({-w-it.S,it.F}); } } puts("-1\n"); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:19:14: 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...