# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52634 | evpipis | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 1083 ms | 71076 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;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int len = 30005, inf = 1e9;
int po[len], pos[len], vis[len];
vector<int> vec[len];
map<int, int> mymap[len];
deque<pair<int, ii> > deq;
int main(){
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d %d", &pos[i], &po[i]);
for (int i = 0; i < m; i++)
vec[pos[i]].pb(po[i]);
int ans = -1;
deq.pb(mp(0, mp(pos[0], po[0])));
while (!deq.empty()){
pair<int, ii> top = deq.front();
deq.pop_front();
int d = top.fi, b = top.se.fi, p = top.se.se;
if (b == pos[1]){
ans = d;
break;
}
if (mymap[b].count(p)) continue;
mymap[b][p] = d;
if (b+p < n)
deq.pb(mp(d+1, mp(b+p, p)));
if (b-p >= 0)
deq.pb(mp(d+1, mp(b-p, p)));
if (vis[b]) continue;
vis[b] = 1;
for (int j = 0; j < vec[b].size(); j++)
deq.push_front(mp(d, mp(b, vec[b][j])));
}
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... |