Submission #691608

# Submission time Handle Problem Language Result Execution time Memory
691608 2023-01-31T10:28:11 Z Dan4Life Rainforest Jumps (APIO21_jumps) C++17
48 / 100
1192 ms 61112 KB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int maxn = (int)2e5+10;
const int maxlg = 24;
const int INF = (int)1e9;

stack<pair<int,int>> S;
int n, pr[maxn], nx[maxn];
int l[maxlg][maxn], r[maxlg][maxn], hi[maxlg][maxn];

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

void init(int N, vector<int> a) {
    n = N; a.insert(a.begin(),-1);
    for(int i = 1; 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; i>=1; 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});
    }
    for(int i = 1; i <= n; i++)
        l[0][i]=pr[i], r[0][i]=nx[i],
        hi[0][i] = (a[pr[i]]<a[nx[i]]?nx[i]:pr[i]);
    calc(l), calc(r), calc(hi);
}

int get_path(int *x, int y, int z, int jmp[][maxn], int rx=1, int tot=0){
    for(int i = maxlg-1; i >= 0; i--)
        if(jmp[i][*x]>=rx and jmp[i][*x]<y)
            if(nx[jmp[i][*x]] 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) {
    A++,B++,C++,D++;
    int x = B; get_path(&x,C,D,l,A);
    if(nx[x]>=C and nx[x]<=D) return 1;
    int ans = get_path(&x,C,D,hi);
    if(nx[x]>=C and nx[x]<=D) return ans+1;
    ans+=get_path(&x,C,D,r);
    return (nx[x]>=C and nx[x]<=D)?ans+1:-1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 161 ms 48548 KB Output is correct
4 Correct 972 ms 60588 KB Output is correct
5 Correct 879 ms 30896 KB Output is correct
6 Correct 939 ms 60584 KB Output is correct
7 Correct 1164 ms 41736 KB Output is correct
8 Correct 1192 ms 60568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 0 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 1 ms 720 KB Output is correct
10 Incorrect 2 ms 720 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 0 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 1 ms 720 KB Output is correct
10 Incorrect 2 ms 720 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 0 ms 592 KB Output is correct
5 Correct 48 ms 48448 KB Output is correct
6 Correct 62 ms 59684 KB Output is correct
7 Correct 29 ms 31020 KB Output is correct
8 Correct 62 ms 59744 KB Output is correct
9 Correct 10 ms 9720 KB Output is correct
10 Correct 61 ms 59792 KB Output is correct
11 Correct 53 ms 60600 KB Output is correct
12 Correct 54 ms 60552 KB Output is correct
13 Correct 57 ms 60344 KB Output is correct
14 Correct 59 ms 59664 KB Output is correct
15 Incorrect 52 ms 60564 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 0 ms 592 KB Output is correct
4 Correct 238 ms 27816 KB Output is correct
5 Correct 997 ms 59668 KB Output is correct
6 Correct 741 ms 10412 KB Output is correct
7 Correct 1110 ms 59680 KB Output is correct
8 Correct 665 ms 21052 KB Output is correct
9 Correct 1051 ms 59684 KB Output is correct
10 Correct 1062 ms 60628 KB Output is correct
11 Correct 979 ms 61112 KB Output is correct
12 Correct 1014 ms 60436 KB Output is correct
13 Correct 698 ms 59720 KB Output is correct
14 Correct 1082 ms 60556 KB Output is correct
15 Correct 1020 ms 60692 KB Output is correct
16 Correct 1073 ms 60688 KB Output is correct
17 Correct 0 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 3 ms 720 KB Output is correct
21 Correct 2 ms 720 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 2 ms 720 KB Output is correct
24 Correct 3 ms 720 KB Output is correct
25 Correct 0 ms 720 KB Output is correct
26 Correct 2 ms 848 KB Output is correct
27 Correct 16 ms 1232 KB Output is correct
28 Correct 21 ms 1232 KB Output is correct
29 Correct 16 ms 1232 KB Output is correct
30 Correct 16 ms 1232 KB Output is correct
31 Correct 17 ms 1232 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 34 ms 34984 KB Output is correct
34 Correct 58 ms 59664 KB Output is correct
35 Correct 54 ms 60436 KB Output is correct
36 Correct 56 ms 59704 KB Output is correct
37 Correct 53 ms 60564 KB Output is correct
38 Correct 53 ms 60780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 0 ms 592 KB Output is correct
4 Correct 238 ms 27816 KB Output is correct
5 Correct 997 ms 59668 KB Output is correct
6 Correct 741 ms 10412 KB Output is correct
7 Correct 1110 ms 59680 KB Output is correct
8 Correct 665 ms 21052 KB Output is correct
9 Correct 1051 ms 59684 KB Output is correct
10 Correct 1062 ms 60628 KB Output is correct
11 Correct 979 ms 61112 KB Output is correct
12 Correct 1014 ms 60436 KB Output is correct
13 Correct 698 ms 59720 KB Output is correct
14 Correct 1082 ms 60556 KB Output is correct
15 Correct 1020 ms 60692 KB Output is correct
16 Correct 1073 ms 60688 KB Output is correct
17 Correct 0 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 3 ms 720 KB Output is correct
21 Correct 2 ms 720 KB Output is correct
22 Correct 3 ms 720 KB Output is correct
23 Correct 2 ms 720 KB Output is correct
24 Correct 3 ms 720 KB Output is correct
25 Correct 0 ms 720 KB Output is correct
26 Correct 2 ms 848 KB Output is correct
27 Correct 16 ms 1232 KB Output is correct
28 Correct 21 ms 1232 KB Output is correct
29 Correct 16 ms 1232 KB Output is correct
30 Correct 16 ms 1232 KB Output is correct
31 Correct 17 ms 1232 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 34 ms 34984 KB Output is correct
34 Correct 58 ms 59664 KB Output is correct
35 Correct 54 ms 60436 KB Output is correct
36 Correct 56 ms 59704 KB Output is correct
37 Correct 53 ms 60564 KB Output is correct
38 Correct 53 ms 60780 KB Output is correct
39 Correct 1 ms 592 KB Output is correct
40 Correct 1 ms 592 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 264 ms 27780 KB Output is correct
43 Correct 790 ms 59684 KB Output is correct
44 Correct 547 ms 10444 KB Output is correct
45 Correct 811 ms 59776 KB Output is correct
46 Correct 450 ms 21108 KB Output is correct
47 Correct 831 ms 59704 KB Output is correct
48 Correct 1098 ms 60592 KB Output is correct
49 Correct 1125 ms 61104 KB Output is correct
50 Correct 1074 ms 60456 KB Output is correct
51 Correct 812 ms 59780 KB Output is correct
52 Correct 1012 ms 60568 KB Output is correct
53 Correct 892 ms 60692 KB Output is correct
54 Correct 1028 ms 60620 KB Output is correct
55 Correct 0 ms 592 KB Output is correct
56 Correct 113 ms 59688 KB Output is correct
57 Correct 1025 ms 59780 KB Output is correct
58 Correct 522 ms 11076 KB Output is correct
59 Correct 817 ms 59692 KB Output is correct
60 Correct 434 ms 21688 KB Output is correct
61 Correct 798 ms 59668 KB Output is correct
62 Correct 1026 ms 60576 KB Output is correct
63 Correct 1014 ms 60676 KB Output is correct
64 Correct 949 ms 60448 KB Output is correct
65 Correct 717 ms 59732 KB Output is correct
66 Correct 1008 ms 60580 KB Output is correct
67 Correct 1119 ms 60948 KB Output is correct
68 Correct 1187 ms 60596 KB Output is correct
69 Correct 0 ms 592 KB Output is correct
70 Correct 1 ms 592 KB Output is correct
71 Correct 2 ms 672 KB Output is correct
72 Correct 2 ms 720 KB Output is correct
73 Correct 3 ms 720 KB Output is correct
74 Correct 2 ms 720 KB Output is correct
75 Correct 3 ms 720 KB Output is correct
76 Correct 1 ms 592 KB Output is correct
77 Correct 0 ms 592 KB Output is correct
78 Correct 2 ms 592 KB Output is correct
79 Correct 2 ms 720 KB Output is correct
80 Correct 2 ms 720 KB Output is correct
81 Correct 1 ms 720 KB Output is correct
82 Correct 3 ms 720 KB Output is correct
83 Correct 2 ms 720 KB Output is correct
84 Correct 1 ms 720 KB Output is correct
85 Correct 2 ms 720 KB Output is correct
86 Correct 18 ms 1232 KB Output is correct
87 Correct 18 ms 1232 KB Output is correct
88 Correct 18 ms 1232 KB Output is correct
89 Correct 16 ms 1232 KB Output is correct
90 Correct 16 ms 1232 KB Output is correct
91 Correct 1 ms 720 KB Output is correct
92 Correct 1 ms 848 KB Output is correct
93 Correct 21 ms 1232 KB Output is correct
94 Correct 11 ms 1232 KB Output is correct
95 Correct 21 ms 1232 KB Output is correct
96 Correct 21 ms 1232 KB Output is correct
97 Correct 17 ms 1232 KB Output is correct
98 Correct 1 ms 592 KB Output is correct
99 Correct 56 ms 59672 KB Output is correct
100 Correct 56 ms 59776 KB Output is correct
101 Correct 56 ms 60364 KB Output is correct
102 Correct 69 ms 59664 KB Output is correct
103 Correct 52 ms 60556 KB Output is correct
104 Correct 54 ms 60804 KB Output is correct
105 Correct 0 ms 592 KB Output is correct
106 Correct 41 ms 34996 KB Output is correct
107 Correct 56 ms 59672 KB Output is correct
108 Correct 51 ms 60432 KB Output is correct
109 Correct 69 ms 59692 KB Output is correct
110 Correct 62 ms 60564 KB Output is correct
111 Correct 53 ms 60948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 161 ms 48548 KB Output is correct
4 Correct 972 ms 60588 KB Output is correct
5 Correct 879 ms 30896 KB Output is correct
6 Correct 939 ms 60584 KB Output is correct
7 Correct 1164 ms 41736 KB Output is correct
8 Correct 1192 ms 60568 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 0 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 720 KB Output is correct
15 Correct 2 ms 720 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 1 ms 720 KB Output is correct
18 Incorrect 2 ms 720 KB Output isn't correct
19 Halted 0 ms 0 KB -