Submission #612684

# Submission time Handle Problem Language Result Execution time Memory
612684 2022-07-29T20:29:44 Z morete Sky Walking (IOI19_walk) C++17
0 / 100
40 ms 6516 KB
#include "bits/stdc++.h"
#include "walk.h"
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<algorithm>

using namespace std;

#define pb push_back
#define snd second
#define fst first

typedef long long int ll;

const ll INF = 1e18;


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) {
	int n, m;
	map<ll, ll> dst; // altura, custo vertical, barra horizontal
	map<ll, vector<ll>> com, fim;

	n = x.size();
	m = l.size();

	for (int i = 0; i < m; i++){ // altura tem que bater pelo enunciado
		com[l[i]].push_back(y[i]);
		fim[r[i]].push_back(y[i]); // sei onde começa e onde acaba
	}

	// tomar cuidado com inicio e fim na mesma altura na mesma barra


	ll ans = INF; //INF

	dst[0] = 0; // altura zero no inicio
	fim[x[0]].pb(0); // depois não é mais válido

	for (int i = 0; i < n; i++){
		set<int> stay;

		for (auto e : com[x[i]]){
			if (dst.count(e)) 
				stay.insert(e); // não apaga essa altura, pode manter o mesmo valor
			else{
				auto it = dst.lower_bound(e);
				auto dit = it;

				if (dit != dst.begin()) // se existe
					dit--;

				ll min = INF; //INF

				if ((it != dst.end()) and ((*it).fst <= h[i])){ // caminho válido
					min = (*it).snd + abs((*it).fst - e);
				}

				if ((dit != dst.end()) and ((*dit).fst <= h[i])){ // caminho válido
					min = (*dit).snd + abs((*dit).fst - e);
				}

				dst[e] = min;
			}

		}

		if (i == n - 1){
			for (auto e : dst)
				ans = min(ans, e.fst + e.snd);

		} 

		for (auto e : fim[x[i]])
			if (!stay.count(e))
				dst.erase(e);
	}

	return ans + x[n - 1] - x[0];
}

// signed main(){
// 	int n, m;
// 	assert(2 == scanf("%d%d", &n, &m));
// 	vector<int> x(n), h(n);
// 	for (int i = 0; i < n; i++)
// 		assert(2 == scanf("%d%d", &x[i], &h[i]));
// 	vector<int> l(m), r(m), y(m);
// 	for (int i = 0; i < m; i++)
// 		assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
// 	int s, g;
// 	assert(2 == scanf("%d%d", &s, &g));
// 	fclose(stdin);

// 	long long result = min_distance(x, h, l, r, y, s, g);

// 	printf("%lld\n", result);
// 	fclose(stdout);
// 	return 0;
// }
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 6516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 6516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -