Submission #981157

# Submission time Handle Problem Language Result Execution time Memory
981157 2024-05-13T00:23:06 Z Darren0724 Rainforest Jumps (APIO21_jumps) C++17
0 / 100
4000 ms 5440 KB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v,a,b;
void init(int N, vector<int> H) {
	n=N;
	v=H;
	a.resize(n,-1);
	b.resize(n,-1);
	vector<int> st;
	for(int i=0;i<n;i++){
		while(st.size()&&v[st.back()]<v[i]){
			st.pop_back();
		}
		a[i]=(st.size()?st.back():-1);
		st.push_back(i);
	}
	st.clear();
	for(int i=n-1;i>=0;i--){
		while(st.size()&&v[st.back()]<v[i]){
			st.pop_back();
		}
		b[i]=(st.size()?st.back():-1);
		st.push_back(i);
	}
}

int minimum_jumps(int A, int B, int C, int D) {
    int ans=0;
	if(v[A]>v[B])return -1;
	int now=A;
	while(now!=C){
		if(a[now]==-1&&b[now]==-1){
			return -1;
		}
		if(a[now]==-1)now=b[now];
		else if(b[now]==-1)now=a[now];
		else{
			int g1=a[now],g2=b[now];
			if(v[g1]<v[g2])swap(g1,g2);
			if(v[g1]<=v[C])now=g1;
			else if(v[g2]<=v[C])now=g2;
			else return -1;
		}
		ans++;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1558 ms 4504 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 145 ms 2220 KB Output is correct
5 Correct 619 ms 4472 KB Output is correct
6 Correct 399 ms 972 KB Output is correct
7 Correct 537 ms 4292 KB Output is correct
8 Correct 385 ms 1736 KB Output is correct
9 Correct 581 ms 4300 KB Output is correct
10 Execution timed out 4078 ms 5440 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 145 ms 2220 KB Output is correct
5 Correct 619 ms 4472 KB Output is correct
6 Correct 399 ms 972 KB Output is correct
7 Correct 537 ms 4292 KB Output is correct
8 Correct 385 ms 1736 KB Output is correct
9 Correct 581 ms 4300 KB Output is correct
10 Execution timed out 4078 ms 5440 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1558 ms 4504 KB Output isn't correct
4 Halted 0 ms 0 KB -