이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
vector<vector<int>> adj;
void init(int n, vector<int> H){
adj.resize(n);
for (int i = 0; i < n; ++i){
for (int j = i; j < n; ++j){
if (H[j] > H[i]){
adj[i].push_back(j);
break;
}
}
for (int j = i; j >= 0; --j){
if (H[j] > H[i]){
adj[i].push_back(j);
break;
}
}
}
}
int minimum_jumps(int a, int b, int c, int d){
queue<pair<int, int>> q;
unordered_set<int> s, f;
for (int i = a; i <= b; ++i){
s.insert(i);
}
for (int i = c; i <= d; ++i){
f.insert(i);
}
for (int i : s){
q.push({0, i});
}
while (!q.empty()){
auto t = q.front();
q.pop();
if (f.find(t.second) != f.end()){
return t.first;
}
for (int i : adj[t.second]){
q.push({t.first + 1, i});
}
}
return -1;
}
/*
signed main(){
//cin.tie(0);
//iostream::sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector<int> k(n);
for (int i = 0; i < n; ++i){
cin >> k[i];
}
init(n, k);
for (int i = 0; i < q; ++i){
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << minimum_jumps(a, b, c, d) << endl;
}
return 0;
}
*/
# | 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... |