Submission #705335

#TimeUsernameProblemLanguageResultExecution timeMemory
705335ToroTNJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
225 ms65592 KiB
#include<bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back int n,m,x,y,st,ed,cnt,go,cost,u,d[30005]; set<int> s[30005]; vector<pair<int,int> > v[30005]; priority_queue<pair<int,int> > pq; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); if(i==1)st=x; if(i==2)ed=x; s[x].insert(y); } for(int i=0;i<n;i++) { for(auto it=s[i].begin();it!=s[i].end();it++) { cnt=0; for(int j=i-(*it);j>=0;j-=(*it)) { ++cnt; v[i].pb({j,cnt}); if(s[j].find(*it)!=s[j].end())break; } cnt=0; for(int j=i+(*it);j<n;j+=(*it)) { ++cnt; v[i].pb({j,cnt}); if(s[j].find(*it)!=s[j].end())break; } } } for(int i=0;i<n;i++)d[i]=1e9; d[st]=0; pq.push({0,st}); while(!pq.empty()) { u=pq.top().Y; pq.pop(); for(int i=0;i<v[u].size();i++) { y=v[u][i].X,cost=v[u][i].Y; if(d[u]+cost<d[y]) { d[y]=d[u]+cost; pq.push({-d[y],y}); } } } if(d[ed]==1e9) { printf("-1\n"); }else { printf("%d\n",d[ed]); } }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=0;i<v[u].size();i++)
      |                     ~^~~~~~~~~~~~
skyscraper.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
#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...