Submission #678094

#TimeUsernameProblemLanguageResultExecution timeMemory
678094hello_there_123Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
335 ms262144 KiB
#include<bits/stdc++.h> using namespace std; vector<pair<int,int> >v[300005]; main(){ cin.tie(0); ios::sync_with_stdio(0); int N,M; cin>>N>>M; vector<pair<int,int> >hi; for(int i=0;i<M;i++){ int a,b; cin>>a>>b; hi.push_back(make_pair(a,b)); } for(int i=0;i<M;i++){ int x = 1; while(hi[i].first-x*hi[i].second>=0){ v[hi[i].first].push_back(make_pair(hi[i].first-x*hi[i].second,x)); x++; } x = 1; while(hi[i].first+x*hi[i].second<N){ v[hi[i].first].push_back(make_pair(hi[i].first+x*hi[i].second,x)); x++; } } priority_queue<pair<int,int>,vector<pair<int,int> >, greater<pair<int,int> > >pq; pq.push(make_pair(0,hi[0].first)); int dist[300005]; for(int i=0;i<300004;i++) dist[i] = 1e9; dist[hi[0].first] = 0; while(!pq.empty()){ int dis = pq.top().first; int no = pq.top().second; pq.pop(); if(dist[no]<dis)continue; for(pair<int,int>p:v[no]){ if(dis+p.second<dist[p.first]){ dist[p.first] = dis+p.second; pq.push(make_pair(dis+p.second,p.first)); } } } if(dist[hi[1].first] == 1e9) cout<<"-1"; else cout<<dist[hi[1].first]; }

Compilation message (stderr)

skyscraper.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
#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...