Submission #429828

# Submission time Handle Problem Language Result Execution time Memory
429828 2021-06-16T09:54:18 Z rumen_m Sky Walking (IOI19_walk) C++17
0 / 100
4000 ms 187972 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
vector <pair <int, int> > g[maxn];
vector <pair <int,int> > inter[maxn];
int ver;
long long dist[maxn];
bool vis[maxn];
priority_queue <pair <long long, int> > q;
long long dijkstra(int a, int b)
{
   // vis[a] = 1;
   for(int i=0;i<ver;i++)
    dist[i] = 1e18;
   dist[a] = 0;
    q.push({(long long)0, a});
    while(!q.empty())
    {
        int v = q.top().second;
        if(vis[v]||dist[v]!=-q.top().first){q.pop();continue;}
        q.pop();
        //cout<<v<<"->"<<dist[v]<<endl;
        vis[v] =1;
        if(v==b)return dist[v];
        for(auto u:g[v])
        {
            //cout<<u.first<<" "<<dist[v]+u.second<<endl;
            if(vis[u.first])continue;
            if(dist[u.first]>dist[v]+u.second)
            {
                dist[u.first]=dist[v]+u.second;
                q.push({-dist[u.first],u.first});
            }
        }
    }
}
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int _g) {
	ver = x.size();
	int i,j;
	for(i=0;i<x.size();i++)
        inter[i].push_back({0,i});

    for(i=0;i<l.size();i++)
    {int prev = -1,id;
        for(j=l[i];j<=r[i];j++)
        {
            if(y[i]>h[j])continue;
            inter[j].push_back({y[i],ver});
            if(prev!=-1)
            {
                g[ver].push_back({prev,x[j]-x[id]});
                g[prev].push_back({ver,x[j]-x[id]});
            }
            prev = ver;
            id = j;
            ver++;
        }
    }
    for(i=0;i<x.size();i++)
    {
        sort(inter[i].begin(),inter[i].end());
        for(j=0;j<inter[i].size()-1;j++)
        {
            //cout<<i<<" :: "<<inter[i][j].first<<" "<<inter[i][j+1].first<<endl;
            g[inter[i][j].second].push_back({inter[i][j+1].second,inter[i][j+1].first-inter[i][j].first});
            g[inter[i][j+1].second].push_back({inter[i][j].second,inter[i][j+1].first-inter[i][j].first});
        }
    }
    //cout<<"OK"<<endl;
   return dijkstra(s,_g);
}

Compilation message

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:41:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(i=0;i<x.size();i++)
      |          ~^~~~~~~~~
walk.cpp:44:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(i=0;i<l.size();i++)
      |             ~^~~~~~~~~
walk.cpp:60:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(i=0;i<x.size();i++)
      |             ~^~~~~~~~~
walk.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(j=0;j<inter[i].size()-1;j++)
      |                 ~^~~~~~~~~~~~~~~~~~
walk.cpp: In function 'long long int dijkstra(int, int)':
walk.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
   37 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47180 KB Output is correct
2 Correct 27 ms 47216 KB Output is correct
3 Correct 27 ms 47260 KB Output is correct
4 Execution timed out 4054 ms 47168 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47180 KB Output is correct
2 Correct 25 ms 47244 KB Output is correct
3 Correct 468 ms 100312 KB Output is correct
4 Correct 766 ms 112164 KB Output is correct
5 Correct 589 ms 103460 KB Output is correct
6 Correct 1057 ms 97400 KB Output is correct
7 Execution timed out 4051 ms 103604 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 57052 KB Output is correct
2 Runtime error 334 ms 187972 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 57052 KB Output is correct
2 Runtime error 334 ms 187972 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47180 KB Output is correct
2 Correct 27 ms 47216 KB Output is correct
3 Correct 27 ms 47260 KB Output is correct
4 Execution timed out 4054 ms 47168 KB Time limit exceeded
5 Halted 0 ms 0 KB -