이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
int n;
vector<int> h, adj[200005];
int seg[800005][2];
void build(int i, int l, int r) {
if(l==r) {
seg[i][0] = 2e9;
seg[i][1] = -2e9;
return;
}
int m = (l+r)/2;
build(i*2+1, l, m);
build(i*2+2, m+1, r);
seg[i][0] = min(seg[i*2+1][0], seg[i*2+2][0]);
seg[i][1] = max(seg[i*2+1][1], seg[i*2+2][1]);
}
void update(int i, int l, int r, int x) {
if(l==r) {
seg[i][0] = seg[i][1] = x;
return;
}
int m = (l+r)/2;
if(x<=m) update(i*2+1, l, m, x);
else update(i*2+2, m+1, r, x);
seg[i][0] = min(seg[i*2+1][0], seg[i*2+2][0]);
seg[i][1] = max(seg[i*2+1][1], seg[i*2+2][1]);
}
int query(int i, int l, int r, int wl, int wr, int j) {
if(wl<=l && wr>=r) return seg[i][j];
if(wl>r || wr<l) return (j==0 ? 2e9 : -2e9);
int m = (l+r)/2;
return (j==0 ? min(query(i*2+1, l, m, wl, wr, j), query(i*2+2, m+1, r, wl, wr, j)) : max(query(i*2+1, l, m, wl, wr, j), query(i*2+2, m+1, r, wl, wr, j)));
}
void init(int N, std::vector<int> H) {
n = N;
h = H;
vector<pii> v;
for(int i=0;i<n;i++) v.push_back({h[i], i});
sort(v.begin(), v.end());
build(0, 0, n-1);
for(int i=n-1;i>=0;i--) {
int x = query(0, 0, n-1, 0, v[i].second-1, 1);
if(x>-2e9) adj[v[i].second].push_back(x);
x = query(0, 0, n-1, v[i].second+1, n-1, 0);
if(x<2e9) adj[v[i].second].push_back(x);
update(0, 0, n-1, v[i].second);
}
}
int minimum_jumps(int A, int B, int C, int D) {
vector<int> mindis(n, 2e9);
priority_queue<pii, vector<pii>, greater<pii>> pq;
for(int i=A;i<=B;i++) {
mindis[i] = 0;
pq.push({0, i});
}
while(!pq.empty()) {
auto [dis, u] = pq.top();
pq.pop();
if(mindis[u]!=dis) continue;
if(u>=C && u<=D) return dis;
for(int v:adj[u]) {
if(mindis[v]>dis+1) {
mindis[v] = dis+1;
pq.push({dis+1, v});
}
}
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:66:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | auto [dis, u] = pq.top();
| ^
# | 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... |