Submission #199569

#TimeUsernameProblemLanguageResultExecution timeMemory
199569handlenameJakarta Skyscrapers (APIO15_skyscraper)C++17
22 / 100
1099 ms79524 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair int n,m,s,e; vector<pair<int,int> > adj[30001]; vector<int> pos[30001]; int dist[30001]; bool vis[30001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m; for (int i=0;i<m;i++){ int b,p; cin>>b>>p; if (i==0) s=b; if (i==1) e=b; pos[p].pb(b); } for (int i=1;i<30001;i++){ memset(vis,false,sizeof(vis)); for (auto j:pos[i]){ vis[j]=true; } sort(pos[i].begin(),pos[i].end()); for (int j=0;j<pos[i].size();j++){ int dis=1; for (int k=pos[i][j]+i;k<n;k+=i){ adj[pos[i][j]].pb(mp(k,dis)); dis++; if (vis[k]) break; } dis=1; for (int k=pos[i][j]-i;k>=0;k-=i){ adj[pos[i][j]].pb(mp(k,dis)); dis++; if (vis[k]) break; } } } memset(dist,-1,sizeof(dist)); priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq; pq.push(mp(0,s)); while (!pq.empty()){ pair<int,int> cur=pq.top(); pq.pop(); if (dist[cur.second]!=-1) continue; dist[cur.second]=cur.first; //cout<<cur.second<<' '<<cur.first<<'\n'; for (auto i:adj[cur.second]){ pq.push(mp(cur.first+i.second,i.first)); } } cout<<dist[e]; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:27:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j=0;j<pos[i].size();j++){
                      ~^~~~~~~~~~~~~~
#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...