제출 #972529

#제출 시각아이디문제언어결과실행 시간메모리
972529sleepntsheep밀림 점프 (APIO21_jumps)C++14
37 / 100
4053 ms8800 KiB
#include "jumps.h" #include <vector> #include <algorithm> int subtask = -1; #define MAX_N 200000 #define MAX_M (2*MAX_N) int N, head[MAX_N], nxt[MAX_M], vv[MAX_M], timer, dd[MAX_N], rt, indeg[MAX_N]; void link(int u, int v) { static int i = 1; nxt[i] = head[u]; vv[i] = v; head[u] = i++; ++indeg[v]; } void init(int N, std::vector<int> H) { ::N = N; if (N <= 200) subtask = 2; else if (N <= 2000) subtask = 3; int flag = 1; for (int i = 1; i < N; ++i) if (H[i] != H[i-1] + 1) flag = 0; if(flag) subtask = 1; static int stk[MAX_N], so; so = 0; for (int i = 0; i < N; stk[so++] = i++) while (so && H[stk[so-1]] < H[i]) link(stk[--so], i); so = 0; for (int i = N - 1; i >= 0; stk[so++] = i--) while (so && H[stk[so-1]] < H[i]) link(stk[--so], i); rt = std::min_element(H.begin(), H.end()) - H.begin(); } int minimum_jumps(int A, int B, int C, int D) { if (subtask == 1) { if (A > D) return -1; if (B >= C) return 0; return C - B; } if(subtask <= 4) { int dd[MAX_N], qu[MAX_N], qh=0, qt=0,z=1e9; for(int j=0;j<N;++j)dd[j]=1e9; for (int i = A; i <= B; ++i) dd[qu[qh++]=i]=0; while(qh-qt) for(int u=qu[qt++],j=head[u];j;j=nxt[j]) if(dd[vv[j]]>dd[u]+1)dd[vv[j]]=dd[u]+1,qu[qh++]=vv[j]; for (int j = C; j <= D; ++j)if(dd[j]!=1e9&&dd[j]<z)z=dd[j]; return(z<1e9?z:-1); } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...