Submission #1071320

# Submission time Handle Problem Language Result Execution time Memory
1071320 2024-08-23T06:41:17 Z LittleOrange Sky Walking (IOI19_walk) C++17
10 / 100
4000 ms 645012 KB
#include "walk.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll big = 1e18;
struct pos{
	ll x,y;
	bool operator<(const pos &o) const{
		return x!=o.x?x<o.x:y<o.y;
	}
	bool operator==(const pos &o) const{
		return x==o.x&&y==o.y;
	}
	bool operator!=(const pos &o) const{
		return x!=o.x||y!=o.y;
	}
};
struct line{
	ll i,v;
	bool operator<(const line &o) const{
		return v>o.v;
	}
};
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) {
	ll n = x.size();
	ll m = y.size();
	vector<pos> ps;
	for(ll i = 0;i<n;i++) ps.push_back({x[i],0});
	for(ll i = 0;i<m;i++){
		for(ll j = l[i];j<=r[i];j++){
			if (h[j]>=y[i]){
				ps.push_back({x[j],y[i]});
			}
		}
	}
	sort(ps.begin(),ps.end());
	ps.erase(unique(ps.begin(),ps.end()),ps.end());
	auto gp = [&](pos p){
		return lower_bound(ps.begin(),ps.end(),p)-ps.begin();
	};
	ll c = ps.size();
	vector<vector<line>> con(c);
	for(ll i = 1;i<c;i++){
		if (ps[i-1].x==ps[i].x){
			ll d = ps[i].y-ps[i-1].y;
			con[i-1].push_back({i,d});
			con[i].push_back({i-1,d});
		}
	}
	for(ll i = 0;i<m;i++){
		vector<ll> v;
		for(ll j = l[i];j<=r[i];j++){
			if (h[j]>=y[i]){
				v.push_back(gp({x[j],y[i]}));
			}
		}
		for(ll j = 1;j<v.size();j++){
			ll d = ps[v[j]].x-ps[v[j-1]].x;
			con[v[j-1]].push_back({v[j],d});
			con[v[j]].push_back({v[j-1],d});
		}
	}
	ll start = gp({x[s],0});
	ll goal = gp({x[g],0});
	vector<ll> dis(c,big);
	priority_queue<line> q;
	q.push({start,0});
	while(q.size()){
		auto [i,v] = q.top();q.pop();
		if(dis[i]<=v) continue;
		dis[i] = v;
		for(auto [j,w] : con[i]){
			q.push({j,v+w});
		}
	}
	ll ans = dis[goal];
	if (ans>=big) ans = -1;
	return ans;
}

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:57:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(ll j = 1;j<v.size();j++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 428 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 868 ms 100064 KB Output is correct
4 Correct 745 ms 106936 KB Output is correct
5 Correct 451 ms 93844 KB Output is correct
6 Correct 1118 ms 81572 KB Output is correct
7 Correct 405 ms 93352 KB Output is correct
8 Correct 1053 ms 129028 KB Output is correct
9 Correct 456 ms 95348 KB Output is correct
10 Correct 1106 ms 154016 KB Output is correct
11 Correct 352 ms 57524 KB Output is correct
12 Correct 171 ms 42928 KB Output is correct
13 Correct 907 ms 133804 KB Output is correct
14 Correct 3869 ms 39908 KB Output is correct
15 Correct 2015 ms 41392 KB Output is correct
16 Correct 259 ms 41908 KB Output is correct
17 Correct 225 ms 39344 KB Output is correct
18 Execution timed out 4066 ms 11688 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11460 KB Output is correct
2 Execution timed out 4062 ms 645012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11460 KB Output is correct
2 Execution timed out 4062 ms 645012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 428 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 868 ms 100064 KB Output is correct
21 Correct 745 ms 106936 KB Output is correct
22 Correct 451 ms 93844 KB Output is correct
23 Correct 1118 ms 81572 KB Output is correct
24 Correct 405 ms 93352 KB Output is correct
25 Correct 1053 ms 129028 KB Output is correct
26 Correct 456 ms 95348 KB Output is correct
27 Correct 1106 ms 154016 KB Output is correct
28 Correct 352 ms 57524 KB Output is correct
29 Correct 171 ms 42928 KB Output is correct
30 Correct 907 ms 133804 KB Output is correct
31 Correct 3869 ms 39908 KB Output is correct
32 Correct 2015 ms 41392 KB Output is correct
33 Correct 259 ms 41908 KB Output is correct
34 Correct 225 ms 39344 KB Output is correct
35 Execution timed out 4066 ms 11688 KB Time limit exceeded
36 Halted 0 ms 0 KB -