Submission #1038943

# Submission time Handle Problem Language Result Execution time Memory
1038943 2024-07-30T09:56:38 Z AmirAli_H1 Sky Walking (IOI19_walk) C++17
24 / 100
599 ms 245072 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "walk.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e6 + 4;
const int maxs = 1e5 + 4;
const int maxlg = 20;
const ll oo = 1e18 + 4;

int sz, n, m;
vector<pll> adj[maxn];
vector<int> A[maxn], ls; pll val[maxn];
ll dis[maxn]; bool mark[maxn];
pii rmq[maxs][maxlg];
priority_queue<pll> qu;

void addE(int i, int j) {
	ll w = abs(val[i].F - val[j].F) + abs(val[i].S - val[j].S);
	adj[i].pb(Mp(j, w)); adj[j].pb(Mp(i, w));
}

int get_max(int l, int r) {
	int j = __lg(r - l);
	return max(rmq[l][j], rmq[r - (1 << j)][j]).S;
}

void get_val(int l, int r, ll x) {
	if (r - l <= 0) return ;
	int j = get_max(l, r);
	if (rmq[j][0].F < x) return ;
	ls.pb(j);
	get_val(l, j, x); get_val(j + 1, r, x);
}

bool cmp(int i, int j) {
	return (val[i].S < val[j].S);
}

void dij(int v) {
	fill(dis, dis + sz, oo); fill(mark, mark + sz, 0);
	dis[v] = 0; qu.push(Mp(-dis[v], v));
	while (!qu.empty()) {
		int v = qu.top().S; qu.pop();
		if (mark[v]) continue;
		mark[v] = 1;
		for (auto f : adj[v]) {
			int u = f.F; ll w = f.S;
			if (dis[v] + w < dis[u]) {
				dis[u] = dis[v] + w;
				qu.push(Mp(-dis[u], u));
			}
		}
	}
}

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
	sz = 0; n = len(h); m = len(y);
	int v1 = sz++;
	val[v1] = Mp(x[s], 0); A[s].pb(v1);
	int v2 = sz++;
	val[v2] = Mp(x[g], 0); A[g].pb(v2);
	
	for (int i = n - 1; i >= 0; i--) {
		rmq[i][0] = Mp(h[i], i);
		for (int j = 1; j < maxlg; j++) {
			if (i + (1 << j) - 1 >= n) break;
			rmq[i][j] = max(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
		}
	}
	
	for (int i = 0; i < m; i++) {
		ls.clear();
		get_val(l[i], r[i] + 1, y[i]);
		sort(all(ls));
		
		int vx = -1, ux = -1;
		for (int j : ls) {
			vx = sz++;
			val[vx] = Mp(x[j], y[i]); A[j].pb(vx);
			if (ux != -1) addE(ux, vx);
			ux = vx;
		}
	}
	
	for (int i = 0; i < n; i++) {
		sort(all(A[i]), cmp);
		for (int j = 1; j < len(A[i]); j++) {
			addE(A[i][j - 1], A[i][j]);
		}
	}
	
	dij(v1);
	if (dis[v2] == oo) return -1;
	else return dis[v2];
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 54360 KB Output is correct
2 Correct 9 ms 54364 KB Output is correct
3 Correct 8 ms 54364 KB Output is correct
4 Correct 9 ms 54364 KB Output is correct
5 Correct 9 ms 54452 KB Output is correct
6 Correct 9 ms 54364 KB Output is correct
7 Correct 9 ms 54364 KB Output is correct
8 Correct 9 ms 54364 KB Output is correct
9 Correct 9 ms 54364 KB Output is correct
10 Correct 9 ms 54620 KB Output is correct
11 Correct 9 ms 54520 KB Output is correct
12 Correct 9 ms 54500 KB Output is correct
13 Correct 10 ms 54488 KB Output is correct
14 Correct 11 ms 54360 KB Output is correct
15 Correct 9 ms 54432 KB Output is correct
16 Correct 9 ms 54364 KB Output is correct
17 Correct 9 ms 54620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 54360 KB Output is correct
2 Correct 9 ms 54364 KB Output is correct
3 Correct 439 ms 138164 KB Output is correct
4 Correct 415 ms 154192 KB Output is correct
5 Correct 252 ms 142164 KB Output is correct
6 Correct 215 ms 133204 KB Output is correct
7 Correct 265 ms 142420 KB Output is correct
8 Correct 550 ms 158288 KB Output is correct
9 Correct 279 ms 140628 KB Output is correct
10 Correct 599 ms 184912 KB Output is correct
11 Correct 204 ms 104532 KB Output is correct
12 Correct 111 ms 93944 KB Output is correct
13 Correct 527 ms 172116 KB Output is correct
14 Correct 102 ms 93264 KB Output is correct
15 Correct 117 ms 93664 KB Output is correct
16 Correct 124 ms 93012 KB Output is correct
17 Correct 105 ms 91980 KB Output is correct
18 Correct 145 ms 97728 KB Output is correct
19 Correct 12 ms 57688 KB Output is correct
20 Correct 37 ms 73440 KB Output is correct
21 Correct 110 ms 89176 KB Output is correct
22 Correct 106 ms 93268 KB Output is correct
23 Correct 152 ms 101200 KB Output is correct
24 Correct 114 ms 91984 KB Output is correct
25 Correct 119 ms 92192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 70224 KB Output is correct
2 Runtime error 165 ms 245072 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 70224 KB Output is correct
2 Runtime error 165 ms 245072 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 54360 KB Output is correct
2 Correct 9 ms 54364 KB Output is correct
3 Correct 8 ms 54364 KB Output is correct
4 Correct 9 ms 54364 KB Output is correct
5 Correct 9 ms 54452 KB Output is correct
6 Correct 9 ms 54364 KB Output is correct
7 Correct 9 ms 54364 KB Output is correct
8 Correct 9 ms 54364 KB Output is correct
9 Correct 9 ms 54364 KB Output is correct
10 Correct 9 ms 54620 KB Output is correct
11 Correct 9 ms 54520 KB Output is correct
12 Correct 9 ms 54500 KB Output is correct
13 Correct 10 ms 54488 KB Output is correct
14 Correct 11 ms 54360 KB Output is correct
15 Correct 9 ms 54432 KB Output is correct
16 Correct 9 ms 54364 KB Output is correct
17 Correct 9 ms 54620 KB Output is correct
18 Correct 9 ms 54360 KB Output is correct
19 Correct 9 ms 54364 KB Output is correct
20 Correct 439 ms 138164 KB Output is correct
21 Correct 415 ms 154192 KB Output is correct
22 Correct 252 ms 142164 KB Output is correct
23 Correct 215 ms 133204 KB Output is correct
24 Correct 265 ms 142420 KB Output is correct
25 Correct 550 ms 158288 KB Output is correct
26 Correct 279 ms 140628 KB Output is correct
27 Correct 599 ms 184912 KB Output is correct
28 Correct 204 ms 104532 KB Output is correct
29 Correct 111 ms 93944 KB Output is correct
30 Correct 527 ms 172116 KB Output is correct
31 Correct 102 ms 93264 KB Output is correct
32 Correct 117 ms 93664 KB Output is correct
33 Correct 124 ms 93012 KB Output is correct
34 Correct 105 ms 91980 KB Output is correct
35 Correct 145 ms 97728 KB Output is correct
36 Correct 12 ms 57688 KB Output is correct
37 Correct 37 ms 73440 KB Output is correct
38 Correct 110 ms 89176 KB Output is correct
39 Correct 106 ms 93268 KB Output is correct
40 Correct 152 ms 101200 KB Output is correct
41 Correct 114 ms 91984 KB Output is correct
42 Correct 119 ms 92192 KB Output is correct
43 Correct 45 ms 70224 KB Output is correct
44 Runtime error 165 ms 245072 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -