Submission #1109604

#TimeUsernameProblemLanguageResultExecution timeMemory
1109604simona1230Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
317 ms262144 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; struct edge { long long x,d; edge(){} edge(long long _x,long long _d) { x=_x; d=_d; } bool operator<(const edge&e)const { return e.d<d; } }; long long n,m; vector<edge> v[100001]; void read() { cin>>n>>m; for(long long i=0;i<m;i++) { long long x,y; cin>>x>>y; for(long long j=x;j<n;j+=y) { //cout<<i<<" "<<j+m<<endl; v[i].push_back({j+m,(j-x)/y}); } for(long long j=x-y;j>=0;j-=y) { //cout<<i<<" "<<j+m<<endl; v[i].push_back({j+m,(x-j)/y}); } //cout<<x+m<<" "<<i<<endl; v[x+m].push_back({i,0}); } } long long d[100001]; priority_queue<edge> q; void dijkstra() { for(long long i=0;i<100000;i++) d[i]=1e18; d[0]=0; q.push({0,0}); while(q.size()) { edge e=q.top(); //cout<<e.x<<endl; q.pop(); if(d[e.x]>=e.d) { for(long long i=0;i<v[e.x].size();i++) { edge nb=v[e.x][i]; if(nb.d+e.d<d[nb.x]) { d[nb.x]=nb.d+e.d; q.push({nb.x,d[nb.x]}); } } } } } int main() { read(); dijkstra(); if(d[1]==1e18)d[1]=-1; cout<<d[1]<<endl; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void dijkstra()':
skyscraper.cpp:64:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             for(long long i=0;i<v[e.x].size();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...