Submission #724749

#TimeUsernameProblemLanguageResultExecution timeMemory
724749tigarJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
918 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll b[30030], p[30030]; vector<int>srapers[30030]; vector<pair<int, int> >graff[30030]; ll dist[30030]; bool check1[30030]; ll INF=LONG_LONG_MAX; void dijkstra(ll cvor) { for(int i=0; i<30030; i++){check1[i]=false; dist[i]=INF;} priority_queue<pair<ll, ll> >ord; dist[cvor]=0; ord.push({0, cvor}); while(!ord.empty()) { int cv=ord.top().second; ord.pop(); if(check1[cv])continue; check1[cv]=true; for(int j=0; j<graff[cv].size(); j++) { ll pp=graff[cv][j].first; dist[pp]=min(dist[pp], dist[cv]+graff[cv][j].second); if(!check1[pp])ord.push({-dist[pp], pp}); } } } int main() { ll m, n; cin>>n>>m; for(int i=0; i<m; i++) { cin>>b[i]>>p[i]; srapers[b[i]].push_back(i); } for(int i=0; i<m; i++) { int br=0; bool ch=false; while(b[i]-br*p[i]>=0 or b[i]+br*p[i]<n) { int j; if(b[i]-br*p[i]>=0) { j=b[i]-br*p[i]; for(int l=0; l<srapers[j].size(); l++) { graff[i].push_back({srapers[j][l], br}); } } if(b[i]+br*p[i]<n) { j=b[i]+br*p[i]; for(int l=0; l<srapers[j].size(); l++) { graff[i].push_back({srapers[j][l], br}); } } br++; } } dijkstra(0); if(dist[1]==INF){cout<<-1; return 0;} cout<<dist[1]; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void dijkstra(ll)':
skyscraper.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int j=0; j<graff[cv].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 for(int l=0; l<srapers[j].size(); l++)
      |                              ~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:60:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for(int l=0; l<srapers[j].size(); l++)
      |                              ~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:45:14: warning: unused variable 'ch' [-Wunused-variable]
   45 |         bool ch=false;
      |              ^~
#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...