답안 #415879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415879 2021-06-01T16:27:25 Z A_D 밀림 점프 (APIO21_jumps) C++14
23 / 100
1601 ms 56768 KB
#include "jumps.h"

#include <bits/stdc++.h>

using namespace std;
const int NN=2e5+100;
const int L=18;
const int INF=1e9;
int a[NN],lo[NN];
bool vis[NN];
int seg[4*NN];
int n;
vector<int> g[NN];
vector<int> vec;
int st[NN][L][2];
int stt[NN][L];
void build()
{
    lo[1]=0;
    for(int i=2;i<=n+1;i++){
        lo[i]=lo[i/2]+1;
    }
	for (int j=1;j<L;j++){
        for (int i=0;i+(1 << j)<=n;i++){
            stt[i][j]=max(stt[i][j-1],stt[i+(1<<(j-1))][j-1]);
        }
    }
}

int get(int L,int R)
{
    if(R<L)assert(0);
    int j = lo[R - L + 1];
    int ret=max(stt[L][j], stt[R - (1 << j) + 1][j]);
    return ret;
}

void init(int N, std::vector<int> H) {
    n=N;
    for(int i=0;i<L;i++){
        st[n+1][i][0]=n+1;
        st[n+1][i][1]=n+1;
    }
    for(int i=0;i<N;i++){
        a[i]=H[i];
        stt[i][0]=a[i];
    }
    build();
    for(int i=0;i<n;i++){
        if(i!=n-1&&get(i,n-1)!=a[i]){
            int ans,l=i+1,r=n-1;
            while(l<=r){
                int mid=(l+r)/2;
                int v=get(i,mid);
                if(v>a[i]){
                    ans=mid;
                    r=mid-1;
                }
                else{
                    l=mid+1;
                }
            }
            g[a[i]].push_back(a[ans]);
        }
        if(i!=0&&get(0,i)!=a[i]){
            int ans,l=0,r=i-1;
            while(l<=r){
                int mid=(l+r)/2;
                int v=get(mid,i);
                if(v>a[i]){
                    ans=mid;
                    l=mid+1;
                }
                else{
                    r=mid-1;
                }
            }
            g[a[i]].push_back(a[ans]);
        }
        sort(g[a[i]].begin(),g[a[i]].end());
        if(g[a[i]].size()>0){
            st[a[i]][0][0]=g[a[i]][0];
        }
        else{
            st[a[i]][0][0]=n+1;
        }
        if(g[a[i]].size()>1){
            st[a[i]][0][1]=g[a[i]][1];
        }
        else{
            st[a[i]][0][1]=n+1;
        }
    }
    for(int j=1;j<L;j++){
        for(int i=1;i<=n;i++){
            int r=i;
            r=st[r][j-1][0];
            r=st[r][j-1][0];
            st[i][j][0]=r;
            r=i;
            r=st[r][j-1][1];
            r=st[r][j-1][1];
            st[i][j][1]=r;
        }
    }
}
int dfs(int u,int tar)
{
    int ret=0;
    for(int i=1;i>=0;i--){
        for(int j=L-1;j>=0;j--){
            int r=st[u][j][i];
            if(r<=tar){
                ret+=(1<<j);
                u=r;
            }
        }
    }
    if(u==tar)return ret;
    else return INF;
}
int minimum_jumps(int A, int B, int C, int D) {
    int u=a[A];
    int tar=a[C];

    int ans=dfs(u,tar);
    if(ans==INF)ans=-1;
    return ans;
}


Compilation message

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:51:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |             int ans,l=i+1,r=n-1;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4936 KB Output is correct
2 Correct 5 ms 4936 KB Output is correct
3 Incorrect 199 ms 46204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4936 KB Output is correct
2 Correct 4 ms 4936 KB Output is correct
3 Correct 4 ms 4936 KB Output is correct
4 Correct 360 ms 28684 KB Output is correct
5 Correct 1454 ms 56640 KB Output is correct
6 Correct 858 ms 13504 KB Output is correct
7 Correct 1424 ms 56656 KB Output is correct
8 Correct 727 ms 22720 KB Output is correct
9 Correct 1399 ms 56680 KB Output is correct
10 Correct 1489 ms 56640 KB Output is correct
11 Correct 1367 ms 56672 KB Output is correct
12 Correct 923 ms 56576 KB Output is correct
13 Correct 1176 ms 56580 KB Output is correct
14 Correct 1420 ms 56640 KB Output is correct
15 Correct 1129 ms 56564 KB Output is correct
16 Correct 1200 ms 56572 KB Output is correct
17 Correct 4 ms 4936 KB Output is correct
18 Correct 4 ms 4936 KB Output is correct
19 Correct 7 ms 4936 KB Output is correct
20 Correct 11 ms 5016 KB Output is correct
21 Correct 9 ms 5064 KB Output is correct
22 Correct 10 ms 5064 KB Output is correct
23 Correct 8 ms 4996 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 4 ms 5064 KB Output is correct
26 Correct 7 ms 5192 KB Output is correct
27 Correct 23 ms 5448 KB Output is correct
28 Correct 24 ms 5448 KB Output is correct
29 Correct 26 ms 5448 KB Output is correct
30 Correct 34 ms 5448 KB Output is correct
31 Correct 23 ms 5448 KB Output is correct
32 Correct 5 ms 4936 KB Output is correct
33 Correct 185 ms 34796 KB Output is correct
34 Correct 278 ms 56660 KB Output is correct
35 Correct 173 ms 56652 KB Output is correct
36 Correct 261 ms 56688 KB Output is correct
37 Correct 250 ms 56536 KB Output is correct
38 Correct 201 ms 56544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4936 KB Output is correct
2 Correct 4 ms 4936 KB Output is correct
3 Correct 4 ms 4936 KB Output is correct
4 Correct 360 ms 28684 KB Output is correct
5 Correct 1454 ms 56640 KB Output is correct
6 Correct 858 ms 13504 KB Output is correct
7 Correct 1424 ms 56656 KB Output is correct
8 Correct 727 ms 22720 KB Output is correct
9 Correct 1399 ms 56680 KB Output is correct
10 Correct 1489 ms 56640 KB Output is correct
11 Correct 1367 ms 56672 KB Output is correct
12 Correct 923 ms 56576 KB Output is correct
13 Correct 1176 ms 56580 KB Output is correct
14 Correct 1420 ms 56640 KB Output is correct
15 Correct 1129 ms 56564 KB Output is correct
16 Correct 1200 ms 56572 KB Output is correct
17 Correct 4 ms 4936 KB Output is correct
18 Correct 4 ms 4936 KB Output is correct
19 Correct 7 ms 4936 KB Output is correct
20 Correct 11 ms 5016 KB Output is correct
21 Correct 9 ms 5064 KB Output is correct
22 Correct 10 ms 5064 KB Output is correct
23 Correct 8 ms 4996 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 4 ms 5064 KB Output is correct
26 Correct 7 ms 5192 KB Output is correct
27 Correct 23 ms 5448 KB Output is correct
28 Correct 24 ms 5448 KB Output is correct
29 Correct 26 ms 5448 KB Output is correct
30 Correct 34 ms 5448 KB Output is correct
31 Correct 23 ms 5448 KB Output is correct
32 Correct 5 ms 4936 KB Output is correct
33 Correct 185 ms 34796 KB Output is correct
34 Correct 278 ms 56660 KB Output is correct
35 Correct 173 ms 56652 KB Output is correct
36 Correct 261 ms 56688 KB Output is correct
37 Correct 250 ms 56536 KB Output is correct
38 Correct 201 ms 56544 KB Output is correct
39 Correct 4 ms 4936 KB Output is correct
40 Correct 5 ms 4968 KB Output is correct
41 Correct 4 ms 5008 KB Output is correct
42 Correct 366 ms 28536 KB Output is correct
43 Correct 1593 ms 56768 KB Output is correct
44 Correct 750 ms 13436 KB Output is correct
45 Correct 1601 ms 56660 KB Output is correct
46 Correct 959 ms 22684 KB Output is correct
47 Correct 1552 ms 56748 KB Output is correct
48 Correct 1460 ms 56768 KB Output is correct
49 Correct 1343 ms 56644 KB Output is correct
50 Correct 1410 ms 56700 KB Output is correct
51 Correct 1242 ms 56588 KB Output is correct
52 Correct 1113 ms 56572 KB Output is correct
53 Correct 1199 ms 56656 KB Output is correct
54 Correct 1304 ms 56556 KB Output is correct
55 Correct 3 ms 4936 KB Output is correct
56 Incorrect 321 ms 56356 KB Output isn't correct
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4936 KB Output is correct
2 Correct 5 ms 4936 KB Output is correct
3 Incorrect 199 ms 46204 KB Output isn't correct
4 Halted 0 ms 0 KB -