답안 #691573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
691573 2023-01-31T09:15:16 Z Dan4Life 밀림 점프 (APIO21_jumps) C++17
23 / 100
4000 ms 62280 KB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back

const int maxn = (int)2e5+10;
const int maxlg = 24;
const int INF = (int)1e9;

int n, h[maxn], pr[maxn], nx[maxn];
int high[maxlg][maxn], low[maxlg][maxn], movR[maxlg][maxn];

void calc(int jmp[][maxn]){
    for(int i = 1; i < maxlg; i++)
        for(int j = 0; j < n; j++)
            if(jmp[i-1][j]!=-1) jmp[i][j] = jmp[i-1][jmp[i-1][j]];
}

void init(int N, vector<int> a) {
    n = N;
    stack<pair<int,int>> S;
    memset(pr,-1,sizeof(pr));
    memset(nx,-1,sizeof(nx));
    memset(low,-1,sizeof(low));
    memset(high,-1,sizeof(high));
    memset(movR,-1,sizeof(movR));
    for(int i = 0; i < (int)a.size(); i++) h[i]=a[i];
    for(int i = 0; i < n; i++){
        while(!S.empty() and S.top().fi<a[i]) S.pop();
        if(!S.empty()) pr[i] = S.top().se;
        S.push({a[i],i});
    }
    while(!S.empty()) S.pop();
    for(int i = n-1; i>=0; i--){
        while(!S.empty() and S.top().fi<a[i]) S.pop();
        if(!S.empty()) nx[i] = S.top().se;
        S.push({a[i],i});
    }
    while(!S.empty()) S.pop();
    for(int i = 0; i < n; i++){
        if(nx[i]!=-1) movR[0][i]=nx[i];
        if(pr[i]!=-1 and nx[i]!=-1){
            bool ok=0;
            if(a[pr[i]]<a[nx[i]]) swap(pr[i],nx[i]),ok=1;
            high[0][i] = pr[i]; low[0][i] = nx[i];
            if(ok) swap(pr[i],nx[i]);
        }
        else{
            if(pr[i]!=-1) low[0][i] = pr[i];
            else low[0][i] = nx[i];
        }
    }
    calc(high), calc(low), calc(movR);
}

int get_path(int *x, int y, int z, int jmp[][maxn], int range=maxn){
    int tot = 0; range = min(range, y);
    for(int i = 20; i >= 0; i--)
        if(jmp[i][*x]!=-1 and jmp[i][*x]<range)
            if(nx[jmp[i][*x]]!=-1 and nx[jmp[i][*x]]<=z)
                *x = jmp[i][*x], tot+=(1<<i);
    return tot;
}

int minimum_jumps(int A, int B, int C, int D) {
    int x = A;
    for(int i = B; i >= A; i--){
        if(nx[i]==-1 or nx[i]>D) continue;
        x=i; break;
    }
    for(int i = A; i <= B; i++) if(nx[i]!=-1 and nx[i]<=D) x=i;
    int num1 = get_path(&x,C,D,high);
    int num2 = get_path(&x,C,D,movR);
    return ((nx[x]>=C and nx[x]<=D)?num1+num2+1:-1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 58204 KB Output is correct
2 Correct 21 ms 58192 KB Output is correct
3 Correct 582 ms 61408 KB Output is correct
4 Execution timed out 4025 ms 62136 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 58168 KB Output is correct
2 Correct 22 ms 58172 KB Output is correct
3 Correct 22 ms 58112 KB Output is correct
4 Correct 22 ms 58136 KB Output is correct
5 Incorrect 24 ms 58160 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 58168 KB Output is correct
2 Correct 22 ms 58172 KB Output is correct
3 Correct 22 ms 58112 KB Output is correct
4 Correct 22 ms 58136 KB Output is correct
5 Incorrect 24 ms 58160 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 58148 KB Output is correct
2 Correct 21 ms 58176 KB Output is correct
3 Correct 26 ms 58144 KB Output is correct
4 Correct 23 ms 58184 KB Output is correct
5 Incorrect 53 ms 60096 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 58168 KB Output is correct
2 Correct 22 ms 58212 KB Output is correct
3 Correct 23 ms 58184 KB Output is correct
4 Correct 176 ms 59244 KB Output is correct
5 Correct 846 ms 60572 KB Output is correct
6 Correct 660 ms 58560 KB Output is correct
7 Correct 739 ms 60592 KB Output is correct
8 Correct 494 ms 58956 KB Output is correct
9 Correct 794 ms 60488 KB Output is correct
10 Correct 1060 ms 62184 KB Output is correct
11 Correct 1054 ms 61976 KB Output is correct
12 Correct 954 ms 61972 KB Output is correct
13 Correct 840 ms 60480 KB Output is correct
14 Correct 1000 ms 61392 KB Output is correct
15 Correct 725 ms 62212 KB Output is correct
16 Correct 828 ms 62096 KB Output is correct
17 Correct 23 ms 58152 KB Output is correct
18 Correct 27 ms 58160 KB Output is correct
19 Correct 24 ms 58120 KB Output is correct
20 Correct 25 ms 58192 KB Output is correct
21 Correct 25 ms 58192 KB Output is correct
22 Correct 25 ms 58192 KB Output is correct
23 Correct 26 ms 58228 KB Output is correct
24 Correct 26 ms 58220 KB Output is correct
25 Correct 27 ms 58132 KB Output is correct
26 Correct 24 ms 58184 KB Output is correct
27 Correct 44 ms 58192 KB Output is correct
28 Correct 40 ms 58192 KB Output is correct
29 Correct 45 ms 58164 KB Output is correct
30 Correct 42 ms 58320 KB Output is correct
31 Correct 40 ms 58148 KB Output is correct
32 Correct 25 ms 58192 KB Output is correct
33 Correct 49 ms 59536 KB Output is correct
34 Correct 62 ms 60508 KB Output is correct
35 Correct 56 ms 61860 KB Output is correct
36 Correct 65 ms 60568 KB Output is correct
37 Correct 60 ms 61384 KB Output is correct
38 Correct 70 ms 62280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 58168 KB Output is correct
2 Correct 22 ms 58212 KB Output is correct
3 Correct 23 ms 58184 KB Output is correct
4 Correct 176 ms 59244 KB Output is correct
5 Correct 846 ms 60572 KB Output is correct
6 Correct 660 ms 58560 KB Output is correct
7 Correct 739 ms 60592 KB Output is correct
8 Correct 494 ms 58956 KB Output is correct
9 Correct 794 ms 60488 KB Output is correct
10 Correct 1060 ms 62184 KB Output is correct
11 Correct 1054 ms 61976 KB Output is correct
12 Correct 954 ms 61972 KB Output is correct
13 Correct 840 ms 60480 KB Output is correct
14 Correct 1000 ms 61392 KB Output is correct
15 Correct 725 ms 62212 KB Output is correct
16 Correct 828 ms 62096 KB Output is correct
17 Correct 23 ms 58152 KB Output is correct
18 Correct 27 ms 58160 KB Output is correct
19 Correct 24 ms 58120 KB Output is correct
20 Correct 25 ms 58192 KB Output is correct
21 Correct 25 ms 58192 KB Output is correct
22 Correct 25 ms 58192 KB Output is correct
23 Correct 26 ms 58228 KB Output is correct
24 Correct 26 ms 58220 KB Output is correct
25 Correct 27 ms 58132 KB Output is correct
26 Correct 24 ms 58184 KB Output is correct
27 Correct 44 ms 58192 KB Output is correct
28 Correct 40 ms 58192 KB Output is correct
29 Correct 45 ms 58164 KB Output is correct
30 Correct 42 ms 58320 KB Output is correct
31 Correct 40 ms 58148 KB Output is correct
32 Correct 25 ms 58192 KB Output is correct
33 Correct 49 ms 59536 KB Output is correct
34 Correct 62 ms 60508 KB Output is correct
35 Correct 56 ms 61860 KB Output is correct
36 Correct 65 ms 60568 KB Output is correct
37 Correct 60 ms 61384 KB Output is correct
38 Correct 70 ms 62280 KB Output is correct
39 Correct 24 ms 58116 KB Output is correct
40 Correct 23 ms 58144 KB Output is correct
41 Correct 23 ms 58192 KB Output is correct
42 Correct 223 ms 59292 KB Output is correct
43 Correct 1002 ms 60488 KB Output is correct
44 Correct 641 ms 58576 KB Output is correct
45 Correct 975 ms 60452 KB Output is correct
46 Correct 579 ms 58988 KB Output is correct
47 Correct 936 ms 60452 KB Output is correct
48 Correct 1089 ms 62112 KB Output is correct
49 Correct 960 ms 62004 KB Output is correct
50 Correct 1010 ms 61856 KB Output is correct
51 Correct 1012 ms 60488 KB Output is correct
52 Correct 1027 ms 61344 KB Output is correct
53 Correct 683 ms 62116 KB Output is correct
54 Correct 926 ms 62116 KB Output is correct
55 Correct 24 ms 58184 KB Output is correct
56 Incorrect 419 ms 60464 KB Output isn't correct
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 58204 KB Output is correct
2 Correct 21 ms 58192 KB Output is correct
3 Correct 582 ms 61408 KB Output is correct
4 Execution timed out 4025 ms 62136 KB Time limit exceeded
5 Halted 0 ms 0 KB -