# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99462 | Shafin666 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 6 ms | 768 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>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
typedef long double ld;
using namespace std;
vector<int> adj[1005], cost[2005];
set<int> s[1005];
int b[2005], dist[1005];
int main()
{
int n, m;
int i, j, k;
int x, y;
cin >> n >> m;
for(int i = 0; i < m; i++) {
cin >> x >> y; b[i] = x;
s[x].insert(y);
}
for(int pos = 0; pos < n; pos++) {
dist[pos] = 1e9+7;
for(int p : s[pos]) {
for(int i = 1; ; i++) {
if(pos + i*p < n) {
adj[pos].pb(pos + i*p);
cost[pos].pb(i);
if(s[pos + i*p].find(p) != s[pos + i*p].end()) break;
} else break;
}
for(int i = 1; ; i++) {
if(pos - i*p >= 0) {
adj[pos].pb(pos - i*p);
cost[pos].pb(i);
if(s[pos - i*p].find(p) != s[pos - i*p].end()) break;
} else break;
}
}
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
dist[b[0]] = 0; pq.push({dist[b[0]], b[0]});
while(!pq.empty()) {
pii p = pq.top();
pq.pop();
int u = p.second; int w = p.first;
for(int i = 0; i < (int) adj[u].size(); i++) {
int c = cost[u][i];
int v = adj[u][i];
if(dist[v] > w+c) {
dist[v] = w+c;
pq.push({dist[v], v});
}
}
}
if(dist[b[1]] >= 1e8) cout << -1 << endl;
else cout << dist[b[1]] << endl;
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... |