# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43579 | RezwanArefin01 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 307 ms | 78924 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;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 30000;
int n, m, b[maxn], p[maxn], dist[maxn];
set<int> st[maxn];
vector<int> adj[maxn], cost[maxn];
void addedge(int u, int v, int c) {
adj[u].push_back(v);
cost[u].push_back(c);
}
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int ans = 0;
scanf("%d %d", &n, &m);
for(int i = 0; i < m; i++) {
scanf("%d %d", &b[i], &p[i]);
st[b[i]].insert(p[i]);
}
for(int pos = 0; pos < n; pos++) {
for(int p : st[pos]) {
for(int i = 1; ; i++) {
int nxt = pos + i * p;
if(nxt < n) {
addedge(pos, nxt, i);
if(st[nxt].find(p) != st[nxt].end()) break;
} else break;
}
for(int i = 1; ; i++) {
int nxt = pos - i * p;
if(nxt >= 0) {
addedge(pos, nxt, i);
if(st[nxt].find(p) != st[nxt].end()) break;
} else break;
}
}
}
priority_queue<ii, vector<ii>, greater<ii> > q;
memset(dist, 63, sizeof dist);
q.push({dist[b[0]] = 0, b[0]});
while(!q.empty()) {
ii x = q.top(); q.pop();
int u = x.second, w = x.first;
for(int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i], c = cost[u][i];
if(dist[v] > w + c) {
dist[v] = w + c;
q.push({dist[v], v});
}
}
}
if(dist[b[1]] >= 1e8) puts("-1");
else cout << dist[b[1]] << 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... |