제출 #1071170

#제출 시각아이디문제언어결과실행 시간메모리
1071170stdfloat밀림 점프 (APIO21_jumps)C++17
23 / 100
931 ms44996 KiB
#include <bits/stdc++.h> #include "jumps.h" // #include "stub.cpp" using namespace std; const int lg = 18; vector<int> h; vector<vector<int>> sp, spr; void init(int n, vector<int> H) { h = H; stack<int> s; vector<int> l(n); for (int i = 0; i < n; i++) { while (!s.empty() && h[s.top()] < h[i]) s.pop(); l[i] = (s.empty() ? -1 : s.top()); s.push(i); } while (!s.empty()) s.pop(); sp.assign(n, vector<int>(lg, -1)); spr = sp; for (int i = n - 1; i >= 0; i--) { while (!s.empty() && h[i] > h[s.top()]) s.pop(); if (s.empty()) sp[i][0] = l[i]; else { sp[i][0] = (l[i] == -1 || h[l[i]] < h[s.top()] ? s.top() : l[i]); spr[i][0] = s.top(); } s.push(i); } for (int i = 1; i < lg; i++) { for (int j = 0; j < n; j++) { if (sp[j][i - 1] != -1) sp[j][i] = sp[sp[j][i - 1]][i - 1]; if (spr[j][i - 1] != -1) spr[j][i] = spr[spr[j][i - 1]][i - 1]; } } } int minimum_jumps(int a, int b, int c, int d) { int cnt = 0; for (int i = lg - 1; i >= 0; i--) { if (sp[a][i] != -1 && h[sp[a][i]] < h[c]) { cnt += (1 << i); a = sp[a][i]; } } for (int i = lg - 1; i >= 0; i--) { if (spr[a][i] != -1 && h[spr[a][i]] < h[c]) { cnt += (1 << i); a = spr[a][i]; } } return (spr[a][0] == c ? cnt + 1 : -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...