Submission #979434

# Submission time Handle Problem Language Result Execution time Memory
979434 2024-05-11T00:31:13 Z vjudge1 Rainforest Jumps (APIO21_jumps) C++17
0 / 100
107 ms 78204 KB
#include "jumps.h"

#include <bits/stdc++.h>
using namespace std;
vector<int>adj[200100];
int vis[200100],d[200100],n,h[200100],rbj[200100][20],obj[200100][20];
vector<int> v;
void init(int N, std::vector<int> H) {
    stack<int> stk;
    for(int i=0;i<N;i++)
        h[i+1]=H[i];
    h[0]=1e9;
    n=N;
    for(int i=0;i<N;i++){
        while(stk.size()&&H[stk.top()]<=H[i])
            stk.pop();
        if(stk.size())
            adj[i+1].push_back(stk.top()+1);
        stk.push(i);
    }
    while(stk.size())stk.pop();
    for(int i=N;i--;){
        while(stk.size()&&H[stk.top()]<=H[i])   
            stk.pop();
        if(stk.size())
            adj[i+1].push_back(rbj[i+1][0]=stk.top()+1);
        stk.push(i);
    }
    for(int i=1;i<=N;i++)if(adj[i].size()>1)
        obj[i][0]=adj[i][H[adj[i][0]]>H[adj[i][1]]];
    else if(adj[i].size())
        obj[i][0]=adj[i][0];
    for(int j=1;j;j++)
        for(int i=1;i<=N;i++)
            rbj[i][j]=rbj[rbj[i][j-1]][j-1],
            obj[i][j]=obj[obj[i][j-1]][j-1];
}
int minimum_jumps(int A, int B, int C, int D) {
    A++,B++,C++,D++;
    A=B;
    int a=A,c=C,d=0;
    for(int i=20;i--;)
        if(h[rbj[a][i]]<=h[c])
            a=rbj[a][i];
    if(a-c)
        return -1;
    a=A;
    for(int i=20;i--;)
        if(h[obj[a][i]]<=h[c])
            a=obj[a][i],d+=1<<i;
    for(int i=20;i--;)
        if(h[rbj[a][i]]<=h[c])
            a=rbj[a][i],d+=1<<i;
    return d;
}

Compilation message

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:33:5: warning: iteration 2147483646 invokes undefined behavior [-Waggressive-loop-optimizations]
   33 |     for(int j=1;j;j++)
      |     ^~~
jumps.cpp:33:17: note: within this loop
   33 |     for(int j=1;j;j++)
      |                 ^
# Verdict Execution time Memory Grader output
1 Runtime error 69 ms 78200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 101 ms 78184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 101 ms 78184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 78160 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 66 ms 78204 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 66 ms 78204 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 69 ms 78200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -