# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
109587 | arman_ferdous | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 6 ms | 3200 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 = 30010;
const int oo = 1e9;
using ii = pair<int,int>;
int n, m;
vector<int> f[N];
map<int,int> has[N];
int dist[N];
vector<ii> g[N];
priority_queue<ii, vector<ii>, greater<ii> > q;
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < m; i++) {
int b, p; scanf("%d %d", &b, &p);
f[b].push_back(p);
}
for(int i = 0; i < n; i++) {
sort(f[i].begin(), f[i].end());
f[i].erase(unique(f[i].begin(),f[i].end()), f[i].end());
for(int p : f[i]) has[i][p] = 1;
}
for(int i = 0; i < n; i++) {
for(int p : f[i]) {
for(int x = i + p, c = 1; x < n; x += p, c++) {
g[i].push_back({c, x});
if(has[x][p]) break;
}
for(int x = i - p, c = 1; x >= 0; x -= p, c++) {
g[i].push_back({c, x});
if(has[x][p]) break;
}
}
}
for(int i = 0; i < n; i++) dist[i] = oo;
q.push({0,0});
dist[0] = 0;
while(!q.empty()) {
auto U = q.top(); q.pop();
int cw = U.first, u = U.second;
for(auto e : g[u]) {
if(dist[e.second] > cw + e.first) {
dist[e.second] = cw + e.first;
q.push({cw + e.first, e.second});
}
}
}
if(dist[1] == oo) puts("-1");
else printf("%d\n", dist[1]);
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... |