Submission #1052552

# Submission time Handle Problem Language Result Execution time Memory
1052552 2024-08-10T16:11:35 Z user736482 Rainforest Jumps (APIO21_jumps) C++17
25 / 100
1111 ms 35632 KB
#include<bits/stdc++.h>
using namespace std;

int lft[200007],rgt[200007],jmpl[200007][18],jmpg[200007][18];
bool czy1=1;
bool odw[200007];
int n;
vector<int>v;
void init(int N,vector<int>V){
    n=N;
    v=V;
    while(v.size()<200007)
        v.push_back(200006);
    stack<int>s;
    lft[200006]=200006;
    rgt[200006]=200006;
    //s.push(n);
    for(int i=0;i<n;i++){
        lft[i]=200006;
        rgt[i]=200006;
    }
    //return;
    for(int i=0;i<n;i++){
        if(s.empty() || v[s.top()]>v[i])
            s.push(i);
        else{
            rgt[s.top()]=i;
            s.pop();
            i--;
        }
    }
    while(s.size()>0) s.pop();
    for(int i=n-1;i>=0;i--){
        if(s.empty() || v[s.top()]>v[i])
            s.push(i);
        else{
            czy1=0;
            lft[s.top()]=i;
            s.pop();
            i++;
        }
    }
    for(int i=0;i<n;i++){
        int pm=lft[i];
        if(v[lft[i]]>v[rgt[i]]){
            lft[i]=rgt[i];
            rgt[i]=pm;
        }
        jmpg[i][0]=rgt[i];
        jmpl[i][0]=lft[i];
    }
    jmpl[200006][0]=200006;
    jmpg[200006][0]=200006;
    for(int i=1;i<18;i++){
        for(int j=0;j<n;j++){
            jmpl[j][i]=jmpl[jmpl[j][i-1]][i-1];
            jmpg[j][i]=jmpg[jmpg[j][i-1]][i-1];
       //     cout<<jmpg[j][i]<<" ";
        }
        jmpl[200006][i]=200006;
        jmpg[200006][i]=200006;
       // cout<<"\n";
    }
    //for(int i=0;i<n;i++)
    //cout<<lft[i]<<" "<<rgt[i]<<"\n";
}
int minimum_jumps(int a,int b,int c,int d){
    if(czy1)
        return c-b;
    if(a==b && c==d){
        int akindex=-1;
        int odp=0;
        while(v[jmpg[a][akindex+1]]<=v[c])
            akindex++;
        if(akindex>=0){
        odp+=1<<akindex;
        //cout<<akindex<<" a ";
        //return 0;
        //cout<<a<<" ";
        a=jmpg[a][akindex];
        //cout<<a<<" ";
        akindex--;}
        while(akindex>=0){
            if(v[jmpg[a][akindex]]>v[c]){
                akindex--;
                continue;
            }
            odp+=1<<akindex;
            a=jmpg[a][akindex];
            akindex--;
            //cout<<a<<" ";
        }
        akindex=-1;
        while(v[jmpl[a][akindex+1]]<=v[c])
            akindex++;
        if(akindex>=0){
        odp+=1<<akindex;
        //cout<<akindex<<" a ";
        //return 0;
        a=jmpl[a][akindex];
        akindex--;}
        while(akindex>=0){
            if(v[jmpl[a][akindex]]>v[c]){
                akindex--;
                continue;
            }
            odp+=1<<akindex;
            a=jmpl[a][akindex];
            akindex--;
            //cout<<a<<" ";
        }
        if(a!=c)
            odp=-1;
        return odp;
    }
    odw[200006]=1;
    int ans[n];
    for(int i=0;i<n;i++){ odw[i]=0; ans[i]=200007;}
    for(int i=a;i<=b;i++) odw[i]=1;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
    for(int i=a;i<=b;i++){
        pq.push({0,i});
    }
    while(!pq.empty()){
        pair<int,int>pom=pq.top();
        pq.pop();
        ans[pom.second]=pom.first;
        if(!odw[lft[pom.second]]){
            odw[lft[pom.second]]=1;
            pq.push({pom.first+1,lft[pom.second]});
        }
        if(!odw[rgt[pom.second]]){
            odw[rgt[pom.second]]=1;
            pq.push({pom.first+1,rgt[pom.second]});
        }
        //return 0;
    }
    int mn=200007;
    for(int i=c;i<=d;i++){
        mn=min(mn,ans[i]);
    }
    if(mn==200007)
        mn=-1;
    //cout<<ans[11];
    return mn;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7372 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 70 ms 32572 KB Output is correct
4 Correct 550 ms 33352 KB Output is correct
5 Correct 492 ms 23240 KB Output is correct
6 Correct 579 ms 33352 KB Output is correct
7 Correct 430 ms 27968 KB Output is correct
8 Correct 552 ms 33352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7504 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 1 ms 7372 KB Output is correct
4 Correct 1 ms 7372 KB Output is correct
5 Correct 2 ms 7308 KB Output is correct
6 Correct 2 ms 7348 KB Output is correct
7 Correct 2 ms 7296 KB Output is correct
8 Correct 2 ms 7348 KB Output is correct
9 Correct 2 ms 7384 KB Output is correct
10 Correct 2 ms 7348 KB Output is correct
11 Correct 2 ms 7348 KB Output is correct
12 Correct 3 ms 7348 KB Output is correct
13 Correct 3 ms 7348 KB Output is correct
14 Correct 3 ms 7348 KB Output is correct
15 Correct 4 ms 7348 KB Output is correct
16 Correct 3 ms 7348 KB Output is correct
17 Correct 3 ms 7348 KB Output is correct
18 Correct 1 ms 7372 KB Output is correct
19 Correct 1 ms 7404 KB Output is correct
20 Correct 2 ms 7348 KB Output is correct
21 Correct 3 ms 7348 KB Output is correct
22 Correct 3 ms 7348 KB Output is correct
23 Correct 3 ms 7348 KB Output is correct
24 Correct 2 ms 7348 KB Output is correct
25 Correct 1 ms 7288 KB Output is correct
26 Correct 1 ms 7372 KB Output is correct
27 Correct 2 ms 7428 KB Output is correct
28 Correct 2 ms 7348 KB Output is correct
29 Correct 2 ms 7348 KB Output is correct
30 Correct 2 ms 7348 KB Output is correct
31 Correct 2 ms 7348 KB Output is correct
32 Correct 2 ms 7348 KB Output is correct
33 Correct 1 ms 7372 KB Output is correct
34 Correct 1 ms 7516 KB Output is correct
35 Correct 1 ms 7348 KB Output is correct
36 Correct 1 ms 7348 KB Output is correct
37 Correct 2 ms 7348 KB Output is correct
38 Correct 1 ms 7348 KB Output is correct
39 Correct 1 ms 7348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7504 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 1 ms 7372 KB Output is correct
4 Correct 1 ms 7372 KB Output is correct
5 Correct 2 ms 7308 KB Output is correct
6 Correct 2 ms 7348 KB Output is correct
7 Correct 2 ms 7296 KB Output is correct
8 Correct 2 ms 7348 KB Output is correct
9 Correct 2 ms 7384 KB Output is correct
10 Correct 2 ms 7348 KB Output is correct
11 Correct 2 ms 7348 KB Output is correct
12 Correct 3 ms 7348 KB Output is correct
13 Correct 3 ms 7348 KB Output is correct
14 Correct 3 ms 7348 KB Output is correct
15 Correct 4 ms 7348 KB Output is correct
16 Correct 3 ms 7348 KB Output is correct
17 Correct 3 ms 7348 KB Output is correct
18 Correct 1 ms 7372 KB Output is correct
19 Correct 1 ms 7404 KB Output is correct
20 Correct 2 ms 7348 KB Output is correct
21 Correct 3 ms 7348 KB Output is correct
22 Correct 3 ms 7348 KB Output is correct
23 Correct 3 ms 7348 KB Output is correct
24 Correct 2 ms 7348 KB Output is correct
25 Correct 1 ms 7288 KB Output is correct
26 Correct 1 ms 7372 KB Output is correct
27 Correct 2 ms 7428 KB Output is correct
28 Correct 2 ms 7348 KB Output is correct
29 Correct 2 ms 7348 KB Output is correct
30 Correct 2 ms 7348 KB Output is correct
31 Correct 2 ms 7348 KB Output is correct
32 Correct 2 ms 7348 KB Output is correct
33 Correct 1 ms 7372 KB Output is correct
34 Correct 1 ms 7516 KB Output is correct
35 Correct 1 ms 7348 KB Output is correct
36 Correct 1 ms 7348 KB Output is correct
37 Correct 2 ms 7348 KB Output is correct
38 Correct 1 ms 7348 KB Output is correct
39 Correct 1 ms 7348 KB Output is correct
40 Correct 2 ms 7504 KB Output is correct
41 Correct 1 ms 7372 KB Output is correct
42 Correct 1 ms 7372 KB Output is correct
43 Correct 1 ms 7372 KB Output is correct
44 Correct 3 ms 7308 KB Output is correct
45 Correct 3 ms 7348 KB Output is correct
46 Correct 2 ms 7500 KB Output is correct
47 Correct 2 ms 7348 KB Output is correct
48 Correct 2 ms 7384 KB Output is correct
49 Correct 3 ms 7348 KB Output is correct
50 Correct 2 ms 7348 KB Output is correct
51 Correct 2 ms 7348 KB Output is correct
52 Correct 3 ms 7348 KB Output is correct
53 Correct 2 ms 7348 KB Output is correct
54 Correct 3 ms 7348 KB Output is correct
55 Correct 2 ms 7348 KB Output is correct
56 Correct 3 ms 7348 KB Output is correct
57 Correct 1 ms 7348 KB Output is correct
58 Correct 31 ms 7300 KB Output is correct
59 Correct 45 ms 7412 KB Output is correct
60 Correct 7 ms 7324 KB Output is correct
61 Correct 51 ms 7412 KB Output is correct
62 Correct 12 ms 7332 KB Output is correct
63 Correct 49 ms 7412 KB Output is correct
64 Correct 9 ms 7412 KB Output is correct
65 Correct 63 ms 7412 KB Output is correct
66 Correct 70 ms 7412 KB Output is correct
67 Correct 52 ms 7412 KB Output is correct
68 Correct 89 ms 7412 KB Output is correct
69 Correct 79 ms 7412 KB Output is correct
70 Correct 76 ms 7412 KB Output is correct
71 Correct 2 ms 7372 KB Output is correct
72 Correct 1 ms 7404 KB Output is correct
73 Correct 2 ms 7348 KB Output is correct
74 Correct 3 ms 7348 KB Output is correct
75 Correct 3 ms 7348 KB Output is correct
76 Correct 3 ms 7348 KB Output is correct
77 Correct 2 ms 7348 KB Output is correct
78 Correct 2 ms 7372 KB Output is correct
79 Correct 1 ms 7372 KB Output is correct
80 Correct 2 ms 7372 KB Output is correct
81 Correct 2 ms 7348 KB Output is correct
82 Correct 2 ms 7348 KB Output is correct
83 Correct 2 ms 7348 KB Output is correct
84 Correct 2 ms 7388 KB Output is correct
85 Correct 2 ms 7516 KB Output is correct
86 Correct 1 ms 7372 KB Output is correct
87 Correct 1 ms 7516 KB Output is correct
88 Correct 1 ms 7348 KB Output is correct
89 Correct 1 ms 7348 KB Output is correct
90 Correct 2 ms 7348 KB Output is correct
91 Correct 1 ms 7348 KB Output is correct
92 Correct 2 ms 7348 KB Output is correct
93 Correct 1 ms 7348 KB Output is correct
94 Correct 3 ms 7452 KB Output is correct
95 Correct 42 ms 7412 KB Output is correct
96 Correct 56 ms 7412 KB Output is correct
97 Correct 50 ms 7412 KB Output is correct
98 Correct 90 ms 7412 KB Output is correct
99 Correct 59 ms 7412 KB Output is correct
100 Correct 2 ms 7348 KB Output is correct
101 Correct 2 ms 7424 KB Output is correct
102 Correct 9 ms 7412 KB Output is correct
103 Correct 9 ms 7412 KB Output is correct
104 Correct 9 ms 7516 KB Output is correct
105 Correct 8 ms 7412 KB Output is correct
106 Correct 11 ms 7412 KB Output is correct
107 Correct 2 ms 7348 KB Output is correct
108 Correct 2 ms 7476 KB Output is correct
109 Correct 2 ms 7412 KB Output is correct
110 Correct 1 ms 7412 KB Output is correct
111 Correct 1 ms 7412 KB Output is correct
112 Correct 2 ms 7412 KB Output is correct
113 Correct 1 ms 7412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7504 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 1 ms 7372 KB Output is correct
4 Correct 1 ms 7372 KB Output is correct
5 Correct 27 ms 33580 KB Output is correct
6 Correct 49 ms 34096 KB Output is correct
7 Correct 14 ms 22728 KB Output is correct
8 Correct 42 ms 35632 KB Output is correct
9 Correct 8 ms 12180 KB Output is correct
10 Correct 32 ms 33584 KB Output is correct
11 Correct 35 ms 33212 KB Output is correct
12 Correct 45 ms 34608 KB Output is correct
13 Incorrect 47 ms 34356 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7372 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 1 ms 7372 KB Output is correct
4 Correct 136 ms 22660 KB Output is correct
5 Correct 593 ms 32508 KB Output is correct
6 Correct 376 ms 13772 KB Output is correct
7 Correct 578 ms 32328 KB Output is correct
8 Correct 353 ms 18220 KB Output is correct
9 Correct 557 ms 32440 KB Output is correct
10 Correct 593 ms 33220 KB Output is correct
11 Incorrect 1111 ms 33096 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7372 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 1 ms 7372 KB Output is correct
4 Correct 136 ms 22660 KB Output is correct
5 Correct 593 ms 32508 KB Output is correct
6 Correct 376 ms 13772 KB Output is correct
7 Correct 578 ms 32328 KB Output is correct
8 Correct 353 ms 18220 KB Output is correct
9 Correct 557 ms 32440 KB Output is correct
10 Correct 593 ms 33220 KB Output is correct
11 Incorrect 1111 ms 33096 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7372 KB Output is correct
2 Correct 1 ms 7372 KB Output is correct
3 Correct 70 ms 32572 KB Output is correct
4 Correct 550 ms 33352 KB Output is correct
5 Correct 492 ms 23240 KB Output is correct
6 Correct 579 ms 33352 KB Output is correct
7 Correct 430 ms 27968 KB Output is correct
8 Correct 552 ms 33352 KB Output is correct
9 Correct 2 ms 7504 KB Output is correct
10 Correct 1 ms 7372 KB Output is correct
11 Correct 1 ms 7372 KB Output is correct
12 Correct 1 ms 7372 KB Output is correct
13 Correct 2 ms 7308 KB Output is correct
14 Correct 2 ms 7348 KB Output is correct
15 Correct 2 ms 7296 KB Output is correct
16 Correct 2 ms 7348 KB Output is correct
17 Correct 2 ms 7384 KB Output is correct
18 Correct 2 ms 7348 KB Output is correct
19 Correct 2 ms 7348 KB Output is correct
20 Correct 3 ms 7348 KB Output is correct
21 Correct 3 ms 7348 KB Output is correct
22 Correct 3 ms 7348 KB Output is correct
23 Correct 4 ms 7348 KB Output is correct
24 Correct 3 ms 7348 KB Output is correct
25 Correct 3 ms 7348 KB Output is correct
26 Correct 1 ms 7372 KB Output is correct
27 Correct 1 ms 7404 KB Output is correct
28 Correct 2 ms 7348 KB Output is correct
29 Correct 3 ms 7348 KB Output is correct
30 Correct 3 ms 7348 KB Output is correct
31 Correct 3 ms 7348 KB Output is correct
32 Correct 2 ms 7348 KB Output is correct
33 Correct 1 ms 7288 KB Output is correct
34 Correct 1 ms 7372 KB Output is correct
35 Correct 2 ms 7428 KB Output is correct
36 Correct 2 ms 7348 KB Output is correct
37 Correct 2 ms 7348 KB Output is correct
38 Correct 2 ms 7348 KB Output is correct
39 Correct 2 ms 7348 KB Output is correct
40 Correct 2 ms 7348 KB Output is correct
41 Correct 1 ms 7372 KB Output is correct
42 Correct 1 ms 7516 KB Output is correct
43 Correct 1 ms 7348 KB Output is correct
44 Correct 1 ms 7348 KB Output is correct
45 Correct 2 ms 7348 KB Output is correct
46 Correct 1 ms 7348 KB Output is correct
47 Correct 1 ms 7348 KB Output is correct
48 Correct 2 ms 7504 KB Output is correct
49 Correct 1 ms 7372 KB Output is correct
50 Correct 1 ms 7372 KB Output is correct
51 Correct 1 ms 7372 KB Output is correct
52 Correct 3 ms 7308 KB Output is correct
53 Correct 3 ms 7348 KB Output is correct
54 Correct 2 ms 7500 KB Output is correct
55 Correct 2 ms 7348 KB Output is correct
56 Correct 2 ms 7384 KB Output is correct
57 Correct 3 ms 7348 KB Output is correct
58 Correct 2 ms 7348 KB Output is correct
59 Correct 2 ms 7348 KB Output is correct
60 Correct 3 ms 7348 KB Output is correct
61 Correct 2 ms 7348 KB Output is correct
62 Correct 3 ms 7348 KB Output is correct
63 Correct 2 ms 7348 KB Output is correct
64 Correct 3 ms 7348 KB Output is correct
65 Correct 1 ms 7348 KB Output is correct
66 Correct 31 ms 7300 KB Output is correct
67 Correct 45 ms 7412 KB Output is correct
68 Correct 7 ms 7324 KB Output is correct
69 Correct 51 ms 7412 KB Output is correct
70 Correct 12 ms 7332 KB Output is correct
71 Correct 49 ms 7412 KB Output is correct
72 Correct 9 ms 7412 KB Output is correct
73 Correct 63 ms 7412 KB Output is correct
74 Correct 70 ms 7412 KB Output is correct
75 Correct 52 ms 7412 KB Output is correct
76 Correct 89 ms 7412 KB Output is correct
77 Correct 79 ms 7412 KB Output is correct
78 Correct 76 ms 7412 KB Output is correct
79 Correct 2 ms 7372 KB Output is correct
80 Correct 1 ms 7404 KB Output is correct
81 Correct 2 ms 7348 KB Output is correct
82 Correct 3 ms 7348 KB Output is correct
83 Correct 3 ms 7348 KB Output is correct
84 Correct 3 ms 7348 KB Output is correct
85 Correct 2 ms 7348 KB Output is correct
86 Correct 2 ms 7372 KB Output is correct
87 Correct 1 ms 7372 KB Output is correct
88 Correct 2 ms 7372 KB Output is correct
89 Correct 2 ms 7348 KB Output is correct
90 Correct 2 ms 7348 KB Output is correct
91 Correct 2 ms 7348 KB Output is correct
92 Correct 2 ms 7388 KB Output is correct
93 Correct 2 ms 7516 KB Output is correct
94 Correct 1 ms 7372 KB Output is correct
95 Correct 1 ms 7516 KB Output is correct
96 Correct 1 ms 7348 KB Output is correct
97 Correct 1 ms 7348 KB Output is correct
98 Correct 2 ms 7348 KB Output is correct
99 Correct 1 ms 7348 KB Output is correct
100 Correct 2 ms 7348 KB Output is correct
101 Correct 1 ms 7348 KB Output is correct
102 Correct 3 ms 7452 KB Output is correct
103 Correct 42 ms 7412 KB Output is correct
104 Correct 56 ms 7412 KB Output is correct
105 Correct 50 ms 7412 KB Output is correct
106 Correct 90 ms 7412 KB Output is correct
107 Correct 59 ms 7412 KB Output is correct
108 Correct 2 ms 7348 KB Output is correct
109 Correct 2 ms 7424 KB Output is correct
110 Correct 9 ms 7412 KB Output is correct
111 Correct 9 ms 7412 KB Output is correct
112 Correct 9 ms 7516 KB Output is correct
113 Correct 8 ms 7412 KB Output is correct
114 Correct 11 ms 7412 KB Output is correct
115 Correct 2 ms 7348 KB Output is correct
116 Correct 2 ms 7476 KB Output is correct
117 Correct 2 ms 7412 KB Output is correct
118 Correct 1 ms 7412 KB Output is correct
119 Correct 1 ms 7412 KB Output is correct
120 Correct 2 ms 7412 KB Output is correct
121 Correct 1 ms 7412 KB Output is correct
122 Correct 1 ms 7504 KB Output is correct
123 Correct 1 ms 7372 KB Output is correct
124 Correct 1 ms 7372 KB Output is correct
125 Correct 1 ms 7372 KB Output is correct
126 Correct 27 ms 33580 KB Output is correct
127 Correct 49 ms 34096 KB Output is correct
128 Correct 14 ms 22728 KB Output is correct
129 Correct 42 ms 35632 KB Output is correct
130 Correct 8 ms 12180 KB Output is correct
131 Correct 32 ms 33584 KB Output is correct
132 Correct 35 ms 33212 KB Output is correct
133 Correct 45 ms 34608 KB Output is correct
134 Incorrect 47 ms 34356 KB Output isn't correct
135 Halted 0 ms 0 KB -