# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103377 | DystoriaX | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1086 ms | 46760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m;
vector<int> pos[300010];
unordered_map<int, unordered_map<int, int> > dist;
int main(){
scanf("%d%d", &n, &m);
int stb, stp, en;
for(int i = 0; i < m; i++){
int b, p;
scanf("%d%d", &b, &p);
if(i == 0) stb = b, stp = p;
if(i == 1) en = b;
pos[b].pb(p);
}
queue<pair<int, int> > q;
q.push({stb, stp});
dist[stb][stp] = 1;
int ans = -1;
while(!q.empty()){
int b, p;
tie(b, p) = q.front(); q.pop();
if(b == en){
ans = dist[b][p] - 1;
break;
}
//cout << b << " " << p << " " << dist[b][p] << endl;
if(b + p < n && dist[b + p][p] == 0){
dist[b + p][p] = dist[b][p] + 1;
q.push({b + p, p});
}
if(b - p >= 0 && dist[b - p][p] == 0){
dist[b - p][p] = dist[b][p] + 1;
q.push({b - p, p});
}
for(auto v : pos[b]){
if(b + v < n && dist[b + v][v] == 0){
dist[b + v][v] = dist[b][p] + 1;
q.push({b + v, v});
}
if(b - v >= 0 && dist[b - v][v] == 0){
dist[b - v][v] = dist[b][p] + 1;
q.push({b - v, v});
}
}
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |