Submission #440625

# Submission time Handle Problem Language Result Execution time Memory
440625 2021-07-02T14:46:22 Z Elegia Rainforest Jumps (APIO21_jumps) C++17
4 / 100
1002 ms 30804 KB
#include "jumps.h"

const int MAX_N = 200010, L = 18;

int N;
int h[MAX_N], left[MAX_N][L], right[MAX_N][L];

void init(int _N, std::vector<int> _H) {
	N = _N;
	std::copy(_H.begin(), _H.end(), h + 1);
	static int stack[MAX_N];
	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		while (cnt && h[i] > h[stack[cnt]])
			right[stack[cnt--]][0] = i;
		left[i][0] = stack[cnt];
		stack[++cnt] = i;
	}
	for (int i = 1; i <= N; ++i) for (int j = 1; j != L; ++j)
		left[i][j] = left[left[i][j - 1]][j - 1];
	std::fill(right[N + 1], right[N + 1] + L, N + 1);
	for (int i = N; i; --i) {
		if (!right[i][0]) right[i][0] = N + 1;
		for (int j = 1; j != L; ++j)
			right[i][j] = right[right[i][j - 1]][j - 1];
	}
}

int minimum_jumps(int A, int B, int C, int D) {
	++A; ++B; ++C; ++D;
	for (int i = L - 1; i >= 0; --i) if (left[D][i] >= C)
		D = left[D][i];
	if (h[B] > h[D]) return -1;
	for (int i = L - 1; i >= 0; --i) if (left[B][i] >= A && h[left[B][i]] < h[D])
		B = left[B][i];
	int ret = 0;
	for (int i = L - 1; i >= 0; --i) if (right[B][i] < C) {
		ret |= 1 << i;
		B = right[B][i];
	}
	return ret + 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 130 ms 24640 KB Output is correct
4 Correct 944 ms 30760 KB Output is correct
5 Correct 976 ms 15768 KB Output is correct
6 Correct 1002 ms 30804 KB Output is correct
7 Correct 828 ms 21056 KB Output is correct
8 Correct 981 ms 30804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Incorrect 2 ms 200 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Incorrect 2 ms 200 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Incorrect 54 ms 24756 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Incorrect 259 ms 14224 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Incorrect 259 ms 14224 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 130 ms 24640 KB Output is correct
4 Correct 944 ms 30760 KB Output is correct
5 Correct 976 ms 15768 KB Output is correct
6 Correct 1002 ms 30804 KB Output is correct
7 Correct 828 ms 21056 KB Output is correct
8 Correct 981 ms 30804 KB Output is correct
9 Correct 0 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 0 ms 200 KB Output is correct
12 Correct 0 ms 200 KB Output is correct
13 Incorrect 2 ms 200 KB Output isn't correct
14 Halted 0 ms 0 KB -