Submission #981198

# Submission time Handle Problem Language Result Execution time Memory
981198 2024-05-13T02:02:29 Z Darren0724 Rainforest Jumps (APIO21_jumps) C++17
0 / 100
4000 ms 36444 KB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v,a,b,pl;
int jump[20][200005];
int jump1[20][200005];
void init(int N, vector<int> H) {
	n=N;
	v=H;
	a.resize(n,-1);
	b.resize(n,-1);
	pl.resize(n+1);
	vector<int> st;
	for(int i=0;i<n;i++){
		pl[v[i]]=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);
	}
	for(int i=0;i<n;i++){
		if(a[i]==-1)swap(a[i],b[i]);
		else if(b[i]==-1)continue;
		else {
			if(v[a[i]]<v[b[i]]){
				swap(a[i],b[i]);
			}
		}
	}
	for(int j=n;j>=1;j--){
		int i=pl[j];
		int now=a[i];
		jump[0][i]=now;
		for(int k=1;k<20;k++){
			if(now==-1){
				jump[k][i]=-1;
				continue;
			}
			else{
				now=jump[k][i]=jump[k-1][now];
			}
		}
		now=b[i];
		jump1[0][i]=now;
		for(int k=1;k<20;k++){
			if(now==-1){
				jump1[k][i]=-1;
				continue;
			}
			else{
				now=jump1[k][i]=jump1[k-1][now];
			}
		}
	}
}
int f(int A, int C) {
    int ans=0;
	int now=A;
	for(int k=19;k>=0;k--){
		int tmp=jump[k][now];
		if(tmp!=-1&&v[tmp]<=v[C]){
			ans+=(1<<k);
			now=tmp;
		}
	}
	for(int k=19;k>=0;k--){
		int tmp=jump1[k][now];
		if(tmp!=-1&&v[tmp]<=v[C]){
			ans+=(1<<k);
			now=tmp;
		}
	}
	if(now!=C)ans=1e9;
	return ans;
}
int minimum_jumps(int A, int B, int C, int D) {
    int ans=1e9;
	for(int i=A;i<=B;i++){
		if(b[i]!=-1&&b[i]<=B)continue;
		for(int j=C;j<=D;j++){
			if(a[j]!=-1&&a[j]>=C)continue;
			ans=min(ans,f(i,j));
		}
	}
	if(ans==1e9)ans=-1;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31064 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Execution timed out 4048 ms 35980 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31064 KB Output is correct
2 Correct 3 ms 31188 KB Output is correct
3 Correct 4 ms 31064 KB Output is correct
4 Correct 4 ms 31064 KB Output is correct
5 Incorrect 5 ms 31064 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31064 KB Output is correct
2 Correct 3 ms 31188 KB Output is correct
3 Correct 4 ms 31064 KB Output is correct
4 Correct 4 ms 31064 KB Output is correct
5 Incorrect 5 ms 31064 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31064 KB Output is correct
2 Correct 4 ms 31208 KB Output is correct
3 Correct 4 ms 31064 KB Output is correct
4 Correct 4 ms 31064 KB Output is correct
5 Correct 66 ms 35392 KB Output is correct
6 Correct 80 ms 36444 KB Output is correct
7 Correct 29 ms 33624 KB Output is correct
8 Incorrect 99 ms 36392 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31060 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Correct 4 ms 31216 KB Output is correct
4 Incorrect 156 ms 33568 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31060 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Correct 4 ms 31216 KB Output is correct
4 Incorrect 156 ms 33568 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31064 KB Output is correct
2 Correct 4 ms 31064 KB Output is correct
3 Execution timed out 4048 ms 35980 KB Time limit exceeded
4 Halted 0 ms 0 KB -