Submission #422771

# Submission time Handle Problem Language Result Execution time Memory
422771 2021-06-10T12:04:24 Z KoD Sky Walking (IOI19_walk) C++17
15 / 100
243 ms 19396 KB
#include <bits/stdc++.h>
#include "walk.h"

using ll = long long;
template <class T> using Vec = std::vector<T>;

constexpr ll INF = std::numeric_limits<ll>::max() / 2;

struct RMQ {
	int size;
	Vec<ll> min;
	RMQ(const int n): size(n), min(2 * n, INF) {}
	void assign(int i, const ll x) {
		i += size;
		min[i] = x;
		while (i > 1) {
			i >>= 1;
			min[i] = std::min(min[2 * i], min[2 * i + 1]);
		}
	}
	ll fold(int l, int r) const {
		l += size;
		r += size;
		ll x = INF;
		while (l < r) {
			if (l & 1) x = std::min(x, min[l++]);
			if (r & 1) x = std::min(x, min[--r]);
			l >>= 1;
			r >>= 1;
		}
		return x;
	}
};

ll min_distance(Vec<int> x, Vec<int> h, Vec<int> l, Vec<int> r, Vec<int> y, int s, int g) {
	const int n = (int) x.size();
	const int m = (int) y.size();
	if (s == 0 and g == n - 1) {
		Vec<Vec<int>> start(n), end(n);
		for (int i = 0; i < m; ++i) {
			start[l[i]].push_back(i);
			end[r[i]].push_back(i);
		}
		Vec<int> cmp = y;
		std::sort(cmp.begin(), cmp.end());
		cmp.erase(std::unique(cmp.begin(), cmp.end()), cmp.end());
		Vec<int> idx(m);
		for (int i = 0; i < m; ++i) {
			idx[i] = std::lower_bound(cmp.begin(), cmp.end(), y[i]) - cmp.begin();
		}
		const int sz = (int) cmp.size();
		RMQ down(sz), up(sz);
		Vec<int> alive(sz);
		for (const int j: start[0]) {
			down.assign(idx[j], y[j] - y[j]);
			up.assign(idx[j], y[j] + y[j]);
			alive[idx[j]] += 1;			
		}
		for (int i = 1; i < n; ++i) {
			const int height = std::upper_bound(cmp.begin(), cmp.end(), h[i]) - cmp.begin();
			for (const auto j: start[i]) {
				const ll d = std::min(y[j] + down.fold(0, idx[j] + 1), up.fold(idx[j], height) - y[j]);
				down.assign(idx[j], d - y[j]);
				up.assign(idx[j], d + y[j]);
				alive[idx[j]] += 1;
			}
			if (i != n - 1) {
				for (const auto j: end[i]) {
					alive[idx[j]] -= 1;
					if (alive[idx[j]] == 0) {
						down.assign(idx[j], INF);
						up.assign(idx[j], INF);
					}
				}
			}
		}
		ll ret = up.fold(0, sz);
		return ret == INF ? -1 : (ret + x[n - 1] - x[0]);
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3380 KB Output is correct
2 Correct 112 ms 8140 KB Output is correct
3 Correct 125 ms 9156 KB Output is correct
4 Correct 197 ms 17076 KB Output is correct
5 Correct 180 ms 15624 KB Output is correct
6 Correct 186 ms 16960 KB Output is correct
7 Correct 103 ms 12740 KB Output is correct
8 Correct 191 ms 19396 KB Output is correct
9 Correct 186 ms 17984 KB Output is correct
10 Correct 143 ms 14896 KB Output is correct
11 Correct 14 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3380 KB Output is correct
2 Correct 112 ms 8140 KB Output is correct
3 Correct 125 ms 9156 KB Output is correct
4 Correct 197 ms 17076 KB Output is correct
5 Correct 180 ms 15624 KB Output is correct
6 Correct 186 ms 16960 KB Output is correct
7 Correct 103 ms 12740 KB Output is correct
8 Correct 191 ms 19396 KB Output is correct
9 Correct 186 ms 17984 KB Output is correct
10 Correct 143 ms 14896 KB Output is correct
11 Correct 14 ms 3404 KB Output is correct
12 Correct 151 ms 9092 KB Output is correct
13 Correct 243 ms 17076 KB Output is correct
14 Correct 214 ms 15536 KB Output is correct
15 Correct 138 ms 14004 KB Output is correct
16 Correct 153 ms 14000 KB Output is correct
17 Correct 155 ms 14000 KB Output is correct
18 Correct 161 ms 14020 KB Output is correct
19 Correct 160 ms 14116 KB Output is correct
20 Correct 121 ms 12580 KB Output is correct
21 Correct 36 ms 6596 KB Output is correct
22 Correct 168 ms 14260 KB Output is correct
23 Correct 150 ms 14568 KB Output is correct
24 Correct 158 ms 15108 KB Output is correct
25 Correct 161 ms 15088 KB Output is correct
26 Correct 156 ms 16216 KB Output is correct
27 Correct 190 ms 16176 KB Output is correct
28 Correct 203 ms 16960 KB Output is correct
29 Correct 197 ms 16964 KB Output is correct
30 Correct 119 ms 12724 KB Output is correct
31 Correct 223 ms 18120 KB Output is correct
32 Correct 113 ms 13896 KB Output is correct
33 Incorrect 146 ms 15424 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -