Submission #133543

#TimeUsernameProblemLanguageResultExecution timeMemory
133543junodeveloperJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
291 ms68196 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define fi first #define se second using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pi; int n,m; int B[30010],P[30010],D[30010]; set<int> ps[30010]; vector<pi> adj[30010]; int main() { scanf("%d%d",&n,&m); int i,j; for(i=0;i<m;i++) { scanf("%d%d", B+i, P+i); ps[B[i]].insert(P[i]); } for(i=0;i<n;i++) { int cur; for(auto& it:ps[i]) { cur=i-it; while(cur>=0) { adj[i].push_back({cur,(i-cur)/it}); if(ps[cur].find(it)!=ps[cur].end()) break; cur-=it; } cur=i+it; while(cur<n) { adj[i].push_back({cur,(cur-i)/it}); if(ps[cur].find(it)!=ps[cur].end()) break; cur+=it; } } } fill(D,D+n,(int)1e9); priority_queue<pi,vector<pi>,greater<pi> > pq; pq.push({0,B[0]}); D[B[0]]=0; while(!pq.empty()) { int w,u; tie(w,u)=pq.top(); pq.pop(); if(D[u]<w) continue; if(u==B[1]) break; for(auto& it:adj[u]) { if(w+it.se<D[it.fi]) { D[it.fi]=w+it.se; pq.push({D[it.fi],it.fi}); } } } printf("%d\n", D[B[1]]==(int)1e9?-1:D[B[1]]); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:16:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
skyscraper.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", 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...