# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66652 | tincamatei | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1090 ms | 64692 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;
const int MAX_N = 30000;
vector<pair<int, int> > graph[MAX_N];
map<pair<int, int>, bool> doges;
int dist[MAX_N];
bool inQueue[MAX_N];
int dijkstra(int n, int src, int dest) {
int firstDist = 0, cons = 0;
deque<deque<int> > pq(n);
memset(dist, 0x3f3f3f3f, sizeof(dist));
dist[src] = 0;
pq.front().push_back(src);
while(cons <= n) {
pq.push_back(deque<int>());
if(pq.front().empty())
++cons;
else
cons = 0;
for(auto nod: pq.front()) {
if(firstDist == dist[nod]) {
if(nod == dest)
return firstDist;
for(auto it: graph[nod])
if(firstDist + it.second < dist[it.first]) {
dist[it.first] = firstDist + it.second;
pq[it.second].push_back(it.first);
}
}
}
pq.pop_front();
++firstDist;
}
return -1;
}
int main() {
int n, m, b, p, src, dest;
scanf("%d%d", &n, &m);
for(int i = 0; i < m; ++i) {
scanf("%d%d", &b, &p);
if(i == 0)
src = b;
if(i == 1)
dest = b;
doges[make_pair(b, p)] = true;
}
for(auto it: doges) {
pair<int, int> doge = it.first;
if(it.second) {
int poz = doge.first - doge.second, cost = 1;
bool foundSimilar = false;
while(poz >= 0 && !foundSimilar) {
graph[doge.first].push_back(make_pair(poz, cost++));
if(doges[make_pair(poz, doge.second)])
foundSimilar = true;
poz -= doge.second;
}
poz = doge.first + doge.second, cost = 1;
foundSimilar = false;
while(poz < n && !foundSimilar) {
graph[doge.first].push_back(make_pair(poz, cost++));
if(doges[make_pair(poz, doge.second)])
foundSimilar = true;
poz += doge.second;
}
}
}
printf("%d", dijkstra(n, src, dest));
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... |