# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158238 | Akashi | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1083 ms | 71104 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>
using namespace std;
struct usu{
int x, y, l;
};
int sgn[] = {-1, 1};
int n, m;
vector <int> v[30005];
queue <usu> q;
unordered_map <int, int> d[30005];
void f(int x, int y, int l){
for(int k = 0; k <= 1 ; ++k){
int nx = x + y * sgn[k];
if(nx < 0 || nx > n) continue ;
if(d[nx][y] == 0){
d[nx][y] = l + 1;
q.push({nx, y, l + 1});
}
}
}
int main()
{
scanf("%d%d", &n, &m);
int x, y, pos;
scanf("%d%d", &x, &y);
d[x][y] = 1;
q.push({x, y, 1});
scanf("%d%d", &x, &y);
v[x].push_back(y);
pos = x;
for(int i = 3; i <= m ; ++i){
scanf("%d%d", &x, &y);
v[x].push_back(y);
}
while(!q.empty()){
int x = q.front().x, y = q.front().y, l = q.front().l;
if(x == pos){
printf("%d", l - 1);
return 0;
}
q.pop();
f(x, y, l);
for(auto it : v[x]) f(x, it, l);
}
printf("-1");
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... |