Submission #718677

# Submission time Handle Problem Language Result Execution time Memory
718677 2023-04-04T14:00:30 Z lam Rainforest Jumps (APIO21_jumps) C++14
0 / 100
263 ms 31480 KB
#include "jumps.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int a[maxn],b[maxn],d[maxn];
vector <int> adj[maxn];
int par[20][maxn];
int f[20][maxn];
void create()
{
    for (int i=0; i<n; i++) f[0][i] = b[i];
    for (int j=1; (1<<j)<=n; j++)
        for (int i=0; i+(1<<j)-1<n; i++)
            f[j][i] = max(f[j-1][i],f[j-1][i+(1<<(j-1))]);
}

int get(int l, int r)
{
    if (l>r) return -1;
    int k=log2(r-l+1);
    return max(f[k][l],f[k][r-(1<<k)+1]);
}

void addedge(int u, int v)
{
    adj[u].push_back(v);
}
void init(int N, std::vector<int> H) {
    n=N;
    for (int i=0; i<n; i++) a[i]=H[i],adj[i].clear();
    deque<int> dq;
    for (int i=0; i<n; i++)
    {
        while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back();
        if (!dq.empty()) par[0][i] = dq.back();
        else par[0][i]=-1;
        dq.push_back(i);
    }
    while (!dq.empty()) dq.pop_back();
    for (int i=n-1; i>=0; i--)
    {
        while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back();
        if (!dq.empty()) b[i] = dq.back(), d[i]=d[dq.back()]+1;
        else b[i] = -1,d[i]=0;
        dq.push_back(i);
    }
    create();
    for (int i=0; i<n; i++)
        for (int j=1; j<20; j++)
            if (par[j-1][i]==-1) par[j][i]=-1;
            else par[j][i]=par[j-1][par[j-1][i]];
}

int minimum_jumps(int A, int B, int C, int D) {
    if (a[A] > a[C]) return -1;
    int smx = get(B+1,C-1);
    if (smx > a[C]) return -1;
    int ans = d[A] - d[C];
    int u=A;
    for (int i=19; i>=0; i--)
        if (par[i][u]!=-1&&a[par[i][u]] < a[C]) u=par[i][u];
    if (a[u] > smx) ans=min(ans,d[u]-d[C]);
    return ans;

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Incorrect 160 ms 31480 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 2 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Incorrect 4 ms 5084 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 2 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Incorrect 4 ms 5084 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Incorrect 41 ms 31100 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5048 KB Output is correct
4 Incorrect 263 ms 19692 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5048 KB Output is correct
4 Incorrect 263 ms 19692 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Incorrect 160 ms 31480 KB Output isn't correct
4 Halted 0 ms 0 KB -