Submission #171726

#TimeUsernameProblemLanguageResultExecution timeMemory
171726dsjongSky Walking (IOI19_walk)C++14
10 / 100
4075 ms835976 KiB
#include "walk.h" #include <bits/stdc++.h> using namespace std; map<pair<int,int>,int> mp; vector<pair<int,int>>adj[1000005]; long long dis[1000005]; long long INF=LONG_LONG_MAX; bool vis[1000005]; void dijkstra(int source){ class prioritize{ public: bool operator ()(pair<int,long long>&p1 ,pair<int,long long>&p2){ return p1.second>p2.second; } }; for(int i=0;i<=1000000;i++) dis[i]=INF; priority_queue<pair<int,long long>,vector<pair<int,long long>>,prioritize>pq; dis[source]=0; pq.push({source,0}); while(!pq.empty()){ pair<int,long long>curr=pq.top(); pq.pop(); int cv=curr.first; long long cw=curr.second; if(vis[cv]) continue; vis[cv]=true; for(auto i:adj[cv]){ if(vis[i.first]) continue; if(i.second+cw<dis[i.first]){ dis[i.first]=i.second+cw; //cout<<i.first<<" "<<dis[i.first]<<endl; pq.push({i.first,dis[i.first]}); } } } } long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, std::vector<int> y, int s, int g) { vector<pair<int,int>>all; int n = x.size(), m = l.size(); mp[{s,0}]=0; mp[{g,0}]=1; int cnt = 2; all.push_back({s,0}); all.push_back({g,0}); for(int i = 0; i < m; i++){ int last=-1; for(int j = l[i]; j <= r[i]; j++){ if(!mp[{j, y[i]}] && h[j] >= y[i]){ all.push_back({j, y[i]}); mp[{j, y[i]}] =cnt; //cout<<mp[{j,y[i]}]<<endl; cnt++; } if(h[j]>=y[i]){ if(last!=-1){ adj[mp[{j,y[i]}]].push_back({mp[{last,y[i]}],x[j]-x[last]}); adj[mp[{last,y[i]}]].push_back({mp[{j,y[i]}],x[j]-x[last]}); //cout<<mp[{j,y[i]}]<<" "<<mp[{last,y[i]}]<<" "<<x[j]-x[last]<<endl; } last = j; } } } //cout<<e; sort(all.begin(),all.end()); for(int i=1; i < all.size(); i++){ if(all[i].first == all[i-1].first){ adj[mp[all[i]]].push_back({mp[all[i-1]], all[i].second-all[i-1].second}); adj[mp[all[i-1]]].push_back({mp[all[i]], all[i].second-all[i-1].second}); } } dijkstra(0); if(dis[1]==INF) return -1; return dis[1]; }

Compilation message (stderr)

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:66:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i < all.size(); i++){
               ~~^~~~~~~~~~~~
walk.cpp:39:6: warning: unused variable 'n' [-Wunused-variable]
  int n = x.size(), m = l.size();
      ^
#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...