답안 #1049006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049006 2024-08-08T11:57:43 Z dozer Sky Walking (IOI19_walk) C++14
10 / 100
4000 ms 356676 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<ll, ll>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define LL node * 2
#define RR node * 2 + 1
#define ll long long


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(), m = l.size();
	vector<map<ll, long long>> dist(n);
	vector<vector<pii>> adj(n);
	vector<vector<ll>> points(n);
	vector<array<ll, 3>> events;
	vector<ll> last(m, -1);

	set<pii> open;
	for (ll i = 0; i < m; i++)
		events.pb({l[i], i, -1}), events.pb({r[i] + 1, i, 1});
	sort(events.begin(), events.end());

	ll it = 0;

	for (ll i = 0; i < n; i++){
		while(it < events.size() && events[it][0] == i){
			ll t = events[it][2], ind = events[it][1];
			if (t == -1) open.insert({-y[ind], ind});
			else open.erase({-y[ind], ind});
			it++;
		}

		auto it2 = open.lower_bound({-h[i], 0});
		while(it2 != open.end()){
			ll ind = it2->nd;
			points[i].pb(y[ind]);
			if (last[ind] != -1){
				adj[i].pb({y[ind], last[ind]});
				adj[last[ind]].pb({y[ind], i});
			}
			last[ind] = i;
			it2++;
		}
		points[i].pb(0);
	}

	for (ll i = 0; i < n; i++){
		sort(points[i].begin(), points[i].end());
		sort(adj[i].begin(), adj[i].end());
	}

	priority_queue<array<long long, 3>> q;
	q.push({0, s, 0});
	dist[s][0] = 0;
	while(!q.empty()){
		array<ll, 3> tmp = q.top();
		q.pop();
		long long X = tmp[1], y = tmp[2], d = -tmp[0];
		if (dist[X][y] < d) continue;
		ll pos = lower_bound(points[X].begin(), points[X].end(), y) - points[X].begin();
		if (pos > 0){
			ll to = points[X][pos - 1];
			ll tmp = d + abs(to - y);
			if (dist[X].count(to) == 0 || dist[X][to] > tmp){
				dist[X][to] = tmp;
				q.push({-tmp, X, to});
			}
		}
		if (pos + 1 < points[X].size()){
			ll to = points[X][pos + 1];
			ll tmp = d + abs(to - y);
			if (dist[X].count(to) == 0 || dist[X][to] > tmp){
				dist[X][to] = tmp;
				q.push({-tmp, X, to});
			}
		}

		pos = lower_bound(adj[X].begin(), adj[X].end(), make_pair(y, (ll)0)) - adj[X].begin();
		while(pos < adj[X].size() && adj[X][pos].st == y){
			ll to = adj[X][pos].nd;
			ll tmp = d + (ll)abs(x[X] - x[to]);
			if (dist[to].count(y) == 0 || dist[to][y] > tmp){
				dist[to][y] = tmp;
				q.push({-tmp, to, y});
			}
			pos++;
		}
	}

	if (dist[g].count(0)) return dist[g][0];
	return -1;
}

/*
int main() {
	fileio();
	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;
}
*/

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:33:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while(it < events.size() && events[it][0] == i){
      |         ~~~^~~~~~~~~~~~~~~
walk.cpp:76:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   if (pos + 1 < points[X].size()){
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~
walk.cpp:86:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   while(pos < adj[X].size() && adj[X][pos].st == y){
      |         ~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 538 ms 92604 KB Output is correct
4 Correct 317 ms 104984 KB Output is correct
5 Correct 106 ms 51112 KB Output is correct
6 Correct 97 ms 46524 KB Output is correct
7 Correct 98 ms 51136 KB Output is correct
8 Correct 823 ms 112596 KB Output is correct
9 Correct 152 ms 56000 KB Output is correct
10 Correct 477 ms 143304 KB Output is correct
11 Correct 187 ms 53944 KB Output is correct
12 Correct 89 ms 47740 KB Output is correct
13 Correct 382 ms 130976 KB Output is correct
14 Correct 76 ms 28504 KB Output is correct
15 Correct 103 ms 48260 KB Output is correct
16 Incorrect 126 ms 48248 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13756 KB Output is correct
2 Execution timed out 4070 ms 356676 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13756 KB Output is correct
2 Execution timed out 4070 ms 356676 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 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 538 ms 92604 KB Output is correct
21 Correct 317 ms 104984 KB Output is correct
22 Correct 106 ms 51112 KB Output is correct
23 Correct 97 ms 46524 KB Output is correct
24 Correct 98 ms 51136 KB Output is correct
25 Correct 823 ms 112596 KB Output is correct
26 Correct 152 ms 56000 KB Output is correct
27 Correct 477 ms 143304 KB Output is correct
28 Correct 187 ms 53944 KB Output is correct
29 Correct 89 ms 47740 KB Output is correct
30 Correct 382 ms 130976 KB Output is correct
31 Correct 76 ms 28504 KB Output is correct
32 Correct 103 ms 48260 KB Output is correct
33 Incorrect 126 ms 48248 KB Output isn't correct
34 Halted 0 ms 0 KB -