Submission #236144

#TimeUsernameProblemLanguageResultExecution timeMemory
236144thtsshz_bgwrswhJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
7 ms2472 KiB
#pragma GCC optimize("Ofast") #include<stdio.h> #include<vector> #include<queue> #include<set> #include<utility> #include<algorithm> using namespace std; int pos[30005],power[30005],dis[30005]; vector<pair<int,int>> g[30005]; set<int> s[30005]; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; int main(){ int i,j,n,m; scanf("%d%d",&n,&m); for(i=0;i<m;i++){ scanf("%d%d",&pos[i],&power[i]); if(i!=1) s[pos[i]].insert(power[i]); } for(i=0;i<m;i++){ for(j=pos[i]+power[i];j<n;j+=power[i]){ if(s[j].count(power[i])) break; //printf("%d\n",j); g[pos[i]].emplace_back(j,(j-pos[i])/power[i]); } for(j=pos[i]-power[i];j>=0;j-=power[i]){ if(s[j].count(power[i])) break; g[pos[i]].emplace_back(j,(pos[i]-j)/power[i]); } // break; } /*for(i=0;i<n;i++){ printf("%d\n",i); for(auto x:g[i]) printf("%d ",x.first); putchar('\n'); }*/ for(i=0;i<n;i++) dis[i]=1000000000; dis[pos[0]]=0; pq.push({0,pos[0]}); while(pq.size()){ auto v=pq.top().second; pq.pop(); for(auto x:g[v]){ if(dis[v]+x.second<dis[x.first]){ dis[x.first]=dis[v]+x.second; pq.push({dis[x.first],x.first}); } } } if(dis[pos[1]]==1000000000) puts("-1"); else printf("%d\n",dis[pos[1]]); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
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:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&pos[i],&power[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...