# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
248367 | sahil_k | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 367 ms | 262148 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 <iostream>
#include <vector>
#include <set>
using namespace std;
int main () {
int n, m;
cin >> n >> m;
vector< pair<int, int> > adj[n];
int bi, pi;
int start, end;
for (int i=0; i<m; i++) {
cin >> bi >> pi;
if (i == 0) start = bi;
if (i == 1) end = bi;
for (int j=1; j<n; j++) {
if (bi-j*pi >= 0) adj[bi].push_back(make_pair(bi-j*pi, j));
if (bi+j*pi < n) adj[bi].push_back(make_pair(bi+j*pi, j));
}
}
set< pair<int, int> > ord;
int dist[n];
bool vis[n];
for (int i=0; i<n; i++) {
dist[i] = 1e9;
vis[i] = false;
}
dist[start] = 0;
ord.insert(make_pair(0, start));
while (ord.size() > 0) {
pair<int, int> cur = *ord.begin();
ord.erase(ord.begin());
vis[cur.second] = true;
for (auto i: adj[cur.second]) {
if (!vis[i.first] && cur.first+i.second < dist[i.first]) {
ord.erase(make_pair(dist[i.first], i.first));
dist[i.first] = cur.first+i.second;
ord.insert(make_pair(dist[i.first], i.first));
}
}
}
if (dist[end] == 1e9) {
cout << -1 << endl;
} else {
cout << dist[end] << endl;
}
}
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... |