답안 #612706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
612706 2022-07-29T21:07:55 Z morete Sky Walking (IOI19_walk) C++17
0 / 100
306 ms 32060 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 = 9e18;


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[x[l[i]]].push_back(y[i]);
		fim[x[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 val = INF; //INF

				if ((it != dst.end())){ // caminho válido
					val = min(val, (*it).snd + abs((*it).fst - e));
				}

				if ((dit != dst.end())){ // caminho válido
					val = min(val, (*dit).snd + abs((*dit).fst - e));
				}

				dst[e] = val;
			}

		}

		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);

		// cout<<i<<" "<<x[i]<<endl;
		// for (auto e : dst)
		// 	cout<<e.fst<<" -- "<<e.snd<<endl;

		// cout<<"--------"<<endl<<endl;		

	}

	return ans + (ll)((ll)x[n - 1] - (ll)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;
// }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 5048 KB Output is correct
2 Correct 90 ms 7000 KB Output is correct
3 Correct 127 ms 9596 KB Output is correct
4 Correct 286 ms 28348 KB Output is correct
5 Correct 289 ms 30808 KB Output is correct
6 Correct 306 ms 30508 KB Output is correct
7 Correct 150 ms 24576 KB Output is correct
8 Correct 212 ms 30120 KB Output is correct
9 Correct 301 ms 32060 KB Output is correct
10 Correct 175 ms 30248 KB Output is correct
11 Incorrect 27 ms 9676 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 5048 KB Output is correct
2 Correct 90 ms 7000 KB Output is correct
3 Correct 127 ms 9596 KB Output is correct
4 Correct 286 ms 28348 KB Output is correct
5 Correct 289 ms 30808 KB Output is correct
6 Correct 306 ms 30508 KB Output is correct
7 Correct 150 ms 24576 KB Output is correct
8 Correct 212 ms 30120 KB Output is correct
9 Correct 301 ms 32060 KB Output is correct
10 Correct 175 ms 30248 KB Output is correct
11 Incorrect 27 ms 9676 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -