Submission #444289

#TimeUsernameProblemLanguageResultExecution timeMemory
444289GiselusJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1086 ms46764 KiB
#include<cstdio> #include<algorithm> #include<queue> #include<vector> #define S 30007 #define M 300 using namespace std; int B[S]; int P[S]; int n,m; int odw[S]; int odw2[S][M+7]; vector < int > doge[S]; priority_queue < pair < int, pair < int , int > >, vector < pair < int , pair < int , int > > > , greater < pair < int , pair < int , int > > > > q; void dijkstra(){ q.push({0,{0,B[0]}}); while(!q.empty()){ int koszt = q.top().first; int pies = q.top().second.first; int gdzie = q.top().second.second; q.pop(); if(!odw[gdzie]){ odw[gdzie] = koszt+1; for(int i = 0; i < doge[gdzie].size();i++){ if(P[doge[gdzie][i]] <= M){ q.push({koszt,{doge[gdzie][i],gdzie}}); }else{ int p = 0; for(int j = gdzie; j >= 0; j -= P[doge[gdzie][i]]){ if(!odw[j]) q.push({koszt+p,{doge[gdzie][i],j}}); p++; } p = 0; for(int j = gdzie; j < n; j += P[doge[gdzie][i]]){ if(!odw[j]) q.push({koszt+p,{doge[gdzie][i],j}}); p++; } } } } if(P[pies] <= M){ if(!odw2[gdzie][P[pies]]){ odw2[gdzie][P[pies]] = 1; if(gdzie - P[pies] >= 0 && !odw2[gdzie-P[pies]][P[pies]]) q.push({koszt+1,{pies, gdzie - P[pies]}}); if(gdzie + P[pies] < n && !odw2[gdzie+P[pies]][P[pies]]) q.push({koszt+1,{pies, gdzie + P[pies]}}); } } } } int main(void){ scanf("%d %d",&n,&m); for(int i = 0; i < m;i++){ scanf("%d %d",&B[i],&P[i]); doge[B[i]].push_back(i); } dijkstra(); if(odw[B[1]]){ printf("%d",odw[B[1]]-1); }else{ printf("-1"); } return 0; } /* 5 3 0 2 1 1 4 1 */

Compilation message (stderr)

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