# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124002 | AyaBenSaad | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 485 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 <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 3; //number of skyscrapers
const int M = 3e4 + 4; //number of doges;
const int inf = 1e9;
int n, m, b[M], p[M], ok;
vector <pair <int, int> > dgin[N], adj[M];
//int dp[M][N];
long long dis[N];
void Dijkstra (int u) {
priority_queue <pair <long long, int> > q;
dis[u] ++;
q.push ({-1, u});
while (q.size()) {
int x = q.top().second;
q.pop();
for (auto e : adj[x]) {
int v = e.first;
long long c = e.second;
if ((!dis[v]) || dis [v] > c + dis[x]){
dis[v] = c + dis[x];
q.push({-dis[v], v});
}
}
}
}
int main () {
scanf ("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &b[i], &p[i]);
// dgin[b[i]].push_back (i);
int a = b[i], k = 1;
while (a-p[i] >= 0) {
adj[b[i]].push_back ({a-p[i], k});
k++;
a -= p[i];
}
a = b[i], k = 1;
while (a+p[i] < n) {
adj[b[i]].push_back ({a+p[i], k});
k++;
a += p[i];
}
}
/*memset (dp, -1, sizeof dp);
int x = solve(0, b[0]);
if(ok) printf("%d\n", x-1);
else puts("-1");*/
Dijkstra(b[0]);
if (dis[b[1]]) printf("%lld\n", dis[b[1]]-1);
else puts("-1");
}
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... |