답안 #1043920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043920 2024-08-05T04:10:25 Z Alihan_8 Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 897820 KB
#include "walk.h"

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define ln '\n'

using i64 = long long;

template <class F, class S>
bool chmin(F &u, const S &v){
	bool flag = false;
	
	if ( u > v ){
		u = v; flag |= true;
	}
	
	return flag;
}

const i64 inf = 1e15;

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 = x.size(), m = l.size();
	
	vector <vector<ar<int,3>>> H(n + 1);
	
	{ // shifting y
		y.pb(0);
		for ( int i = m; i > 0; i-- ){
			y[i] = y[i - 1];
		} y[0] = 0;
	}
	
	for ( int i = 1; i <= m; i++ ){
		H[l[i - 1]].pb({1, y[i], i});
		H[r[i - 1] + 1].pb({0, y[i], i});
	}
	
	set <pair<int,int>> st;
	
	vector <vector<int>> a(n, {0}), mp(m + 1);
	
	auto V = a;
	
	for ( int i = 0; i < n; i++ ){
		for ( auto &[t, y, j]: H[i] ){
			if ( t > 0 ){
				st.insert({y, j});
			} else st.erase({y, j});
		}
		
		auto it = st.begin();
		
		while ( it != st.end() && it -> first <= h[i] ){
			a[i].pb(it -> second);
			V[i].pb(it -> first);
			mp[it -> second].pb(i);
			it = next(it);
		}
	}
	
	vector <vector<i64>> dp(n);
	vector <vector<int>> id(n);
	
	for ( int i = 0; i < n; i++ ){
		sort(all(a[i]), [&](int &u, int &v){
			return y[u] < y[v];
		});
		
		sort(all(V[i]));
		
		int s = a[i].size();
		dp[i].resize(s, inf);
		id[i].resize(s);
		
		for ( int j = 1; j < s; j++ ){
			int x = a[i][j];
			
			id[i][j] = lower_bound(all(mp[x]), i) - mp[x].begin();
		}
	}
	
	dp[s][0] = 0;
	
	priority_queue <ar<i64,3>> q;
	
	q.push({0, s, 0});
	
	while ( !q.empty() ){
		auto [val, u, j] = q.top();
		q.pop();
		
		if ( -val != dp[u][j] ) continue;
		
		if ( j != 0 ){ // using skywalk a[u][j]
			int t = a[u][j];
			
			for ( auto i: {id[u][j] - 1, id[u][j] + 1} ){
				
				if ( i < 0 || i >= (int)mp[t].size() ){
					continue;
				}
				
				int v = mp[t][i], nxt = lower_bound(all(V[v]), y[t]) - V[v].begin();
				
				if ( chmin(dp[v][nxt], dp[u][j] + abs(x[v] - x[u])) ){
					q.push({-dp[v][nxt], v, nxt});
				}
			}
		}
		
		for ( auto i: {j + 1, j - 1} ){
			if ( i < 0 || i >= (int)dp[u].size() ){
				continue;
			}
			
			if ( chmin(dp[u][i], dp[u][j] + abs(y[a[u][j]] - y[a[u][i]])) ){
				q.push({-dp[u][i], u, i});
			}
		}
	}
	
	i64 ans = dp[g][0];
	
	if ( ans == inf ){
		ans = -1;
	}
	
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 1 ms 428 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 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 0 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 272 ms 33120 KB Output is correct
4 Correct 276 ms 51656 KB Output is correct
5 Correct 129 ms 46120 KB Output is correct
6 Correct 135 ms 44316 KB Output is correct
7 Correct 144 ms 46228 KB Output is correct
8 Correct 338 ms 38344 KB Output is correct
9 Correct 163 ms 44860 KB Output is correct
10 Correct 352 ms 61152 KB Output is correct
11 Correct 130 ms 28616 KB Output is correct
12 Correct 102 ms 37164 KB Output is correct
13 Correct 297 ms 56516 KB Output is correct
14 Correct 90 ms 36852 KB Output is correct
15 Correct 110 ms 39148 KB Output is correct
16 Correct 102 ms 35736 KB Output is correct
17 Correct 94 ms 34416 KB Output is correct
18 Correct 144 ms 49216 KB Output is correct
19 Correct 4 ms 2140 KB Output is correct
20 Correct 41 ms 17860 KB Output is correct
21 Correct 87 ms 31432 KB Output is correct
22 Correct 106 ms 37064 KB Output is correct
23 Correct 138 ms 44356 KB Output is correct
24 Correct 99 ms 35788 KB Output is correct
25 Correct 102 ms 34516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 10652 KB Output is correct
2 Correct 2946 ms 147660 KB Output is correct
3 Execution timed out 4099 ms 897820 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 10652 KB Output is correct
2 Correct 2946 ms 147660 KB Output is correct
3 Execution timed out 4099 ms 897820 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 1 ms 428 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 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 0 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 272 ms 33120 KB Output is correct
21 Correct 276 ms 51656 KB Output is correct
22 Correct 129 ms 46120 KB Output is correct
23 Correct 135 ms 44316 KB Output is correct
24 Correct 144 ms 46228 KB Output is correct
25 Correct 338 ms 38344 KB Output is correct
26 Correct 163 ms 44860 KB Output is correct
27 Correct 352 ms 61152 KB Output is correct
28 Correct 130 ms 28616 KB Output is correct
29 Correct 102 ms 37164 KB Output is correct
30 Correct 297 ms 56516 KB Output is correct
31 Correct 90 ms 36852 KB Output is correct
32 Correct 110 ms 39148 KB Output is correct
33 Correct 102 ms 35736 KB Output is correct
34 Correct 94 ms 34416 KB Output is correct
35 Correct 144 ms 49216 KB Output is correct
36 Correct 4 ms 2140 KB Output is correct
37 Correct 41 ms 17860 KB Output is correct
38 Correct 87 ms 31432 KB Output is correct
39 Correct 106 ms 37064 KB Output is correct
40 Correct 138 ms 44356 KB Output is correct
41 Correct 99 ms 35788 KB Output is correct
42 Correct 102 ms 34516 KB Output is correct
43 Correct 33 ms 10652 KB Output is correct
44 Correct 2946 ms 147660 KB Output is correct
45 Execution timed out 4099 ms 897820 KB Time limit exceeded
46 Halted 0 ms 0 KB -