답안 #416858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416858 2021-06-03T06:16:38 Z CSQ31 밀림 점프 (APIO21_jumps) C++14
0 / 100
328 ms 37500 KB
#include "jumps.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
const int MAXN = 2e5+5;
vii adj(MAXN);
int hpar[20][MAXN],lpar[20][MAXN];
vector<int>H;
void init(int n, vector<int>h){
	H = h;
	stack<pii>stk;
	for(int i=0;i<n;i++){
		while(!stk.empty() && stk.top().fi < h[i])stk.pop();
		if(!stk.empty())adj[i+1].pb(stk.top().se+1);
		stk.push({h[i],i});
	}
	while(!stk.empty())stk.pop();
	for(int i=n-1;i>=0;i--){
	    while(!stk.empty() && stk.top().fi < h[i])stk.pop();
		if(!stk.empty())adj[i+1].pb(stk.top().se+1);
		stk.push({h[i],i});
	}
	for(int i=1;i<=n;i++){
		if(sz(adj[i]) >1){
			hpar[0][i] = h[adj[i][0]-1]<h[adj[i][1]-1] ? h[adj[i][1]-1] : h[adj[i][0]-1];
			lpar[0][i] = h[adj[i][0]-1]>h[adj[i][1]-1] ? h[adj[i][1]-1] : h[adj[i][0]-1];
		}
		else if(sz(adj[i])) lpar[0][i] = h[adj[i][0]-1];
	}
	for(int j=1;j<20;j++){
		for(int i=1;i<=n;i++){
			hpar[j][i] = hpar[j-1][hpar[j-1][i]];
			lpar[j][i] = lpar[j-1][lpar[j-1][i]];
		}
	}
	
}
int minimum_jumps(int a,int b,int c,int d){
	a++;
	b++;
	c++;
	d++;
	if(a==b && c==d){
		int cur = a;
		int ans = 0;
		for(int i=19;i>=0;i--){
			if(hpar[i][cur] && H[hpar[i][cur]-1] <= H[d-1]){
				ans+=(1<<i);
				cur = hpar[i][cur];
			}
		}
		for(int i=19;i>=0;i--){
			if(lpar[i][cur] && H[lpar[i][cur]-1] <= H[d-1]){
				ans+=(1<<i);
				cur = lpar[i][cur];
			}
		}
		if(cur == d)return ans;
		else return -1;
		
	}	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5192 KB Output is correct
2 Correct 3 ms 5192 KB Output is correct
3 Incorrect 139 ms 37500 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5192 KB Output is correct
2 Correct 4 ms 5192 KB Output is correct
3 Correct 5 ms 5192 KB Output is correct
4 Incorrect 328 ms 23388 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5192 KB Output is correct
2 Correct 4 ms 5192 KB Output is correct
3 Correct 5 ms 5192 KB Output is correct
4 Incorrect 328 ms 23388 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5192 KB Output is correct
2 Correct 3 ms 5192 KB Output is correct
3 Incorrect 139 ms 37500 KB Output isn't correct
4 Halted 0 ms 0 KB -