# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43578 | 2018-03-17T23:51:23 Z | RezwanArefin01 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 4 ms | 3568 KB |
#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[1] >= 1e8) puts("-1"); else cout << dist[1] << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3192 KB | Output is correct |
2 | Incorrect | 4 ms | 3296 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3296 KB | Output is correct |
2 | Incorrect | 4 ms | 3368 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3568 KB | Output is correct |
2 | Incorrect | 3 ms | 3568 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3568 KB | Output is correct |
2 | Incorrect | 3 ms | 3568 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3568 KB | Output is correct |
2 | Incorrect | 4 ms | 3568 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |