이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int n;
vector<int> h, pge, nge, dp;
vector<vector<int>> gp;
int a, b, c, d;
vector<int> PNG(vector<int> v, bool b)
{
if (b) reverse(v.begin(), v.end());
vector<int> tmp(v.size());
stack<int> s;
s.push(0);
tmp[0] = -1;
for (int i = 1; i < v.size(); i++)
{
while (!s.empty() && v[s.top()] < v[i]) s.pop();
tmp[i] = (s.empty() ? -1 : s.top());
s.push(i);
}
if (b) {
reverse(tmp.begin(), tmp.end());
for (int& i : tmp) i = (i == -1 ? -1 : n - 1 - i);
}
return tmp;
}
void dfs(int u)
{
if (u >= c && u <= d) { dp[u] = 0; return; }
if (dp[u] != 2e9) return;
int x = 2e9, y = 2e9;
if (!gp[u].empty() ) dfs(gp[u][0]), x = dp[gp[u][0]];
if ( gp[u].size() > 1) dfs(gp[u][1]), y = dp[gp[u][1]];
dp[u] = min(int(2e9), min(x, y) + 1);
}
void init(int N, vector<int> H)
{
n = N;
h = H;
pge = PNG(H, 0);
nge = PNG(H, 1);
gp = vector<vector<int>>(n);
for (int i = 0; i < n; i++)
{
if (pge[i] != -1) gp[i].push_back(pge[i]);
if (nge[i] != -1) gp[i].push_back(nge[i]);
}
}
int minimum_jumps(int A, int B, int C, int D)
{
a = A, b = B, c = C, d = D;
dp = vector<int>(n, 2e9);
int mn = 2e9;
for (int i = a; i <= b; i++) dfs(i), mn = min(mn, dp[i]);
return (mn == 2e9 ? -1 : mn);
}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'std::vector<int> PNG(std::vector<int>, bool)':
jumps.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |