제출 #934629

#제출 시각아이디문제언어결과실행 시간메모리
934629MinaRagy06밀림 점프 (APIO21_jumps)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#ifdef MINA
#include "grader.cpp"
#endif
#include "jumps.h"
using namespace std;
#define ll long long

const int N = 200'005;
int nxt[N], prv[N][18];
vector<int> a;
void init(int n, vector<int> _a) {
	a = _a;
	stack<int> s;
	s.push(n);
	for (int i = n - 1; i >= 0; i--) {
		while (s.top() != n && a[s.top()] < a[i]) {
			s.pop();
		}
		nxt[i] = s.top();
		s.push(i);
	}
	while (s.size()) s.pop();
	s.push(-1);
	for (int i = 0; i < n; i++) {
		while (s.top() != -1 && a[s.top()] < a[i]) {
			s.pop();
		}
		prv[i][0] = s.top();
		s.push(i);
	}
	for (int j = 1; j < 18; j++) {
		for (int i = 0; i < n; i++) {
			prv[i][j] = prv[i][j - 1];
			if (prv[i][j] != -1) prv[i][j] = prv[prv[i][j]][j - 1];
		}
	}
}
int minimum_jumps(int l, int r, int s, int e) {
	if (nxt[r] > e) {
		return -1;
	}
	int mx = -1, lst = -1;
	for (int i = r; i >= l; i--) {
		if (a[i] > mx) {
			mx = a[i];
			if (nxt[i] <= e) {
				lst = i;
			} else {
				break;
			}
		}
	}
	if (lst == -1) return -1;
	int cur = lst, ans = 0;
	while (cur < s) {
		while (prv[cur] != -1 && nxt[prv[cur]] <= e && nxt[prv[cur]] != nxt[cur] && nxt[cur] < s) {
			cur = prv[cur];
			ans++;
		}
		cur = nxt[cur];
		ans++;
	}
	if (cur > e) {
		return -1;
	}
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:57:19: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   57 |   while (prv[cur] != -1 && nxt[prv[cur]] <= e && nxt[prv[cur]] != nxt[cur] && nxt[cur] < s) {
      |          ~~~~~~~~~^~~~~
jumps.cpp:57:31: error: invalid types 'int [200005][int [18]]' for array subscript
   57 |   while (prv[cur] != -1 && nxt[prv[cur]] <= e && nxt[prv[cur]] != nxt[cur] && nxt[cur] < s) {
      |                               ^
jumps.cpp:57:53: error: invalid types 'int [200005][int [18]]' for array subscript
   57 |   while (prv[cur] != -1 && nxt[prv[cur]] <= e && nxt[prv[cur]] != nxt[cur] && nxt[cur] < s) {
      |                                                     ^
jumps.cpp:58:17: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   58 |    cur = prv[cur];
      |          ~~~~~~~^
      |                 |
      |                 int*