# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684134 | kusssso | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 623 ms | 6860 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;
using ll = long long;
const int N = 30005;
const ll inf = 1e18;
int n, m;
int b[N], p[N];
ll d[N];
vector<int> power[N];
vector<pair<int, ll>> g[N];
struct kek {
int u;
ll du;
bool operator < (const kek& oth) const {
return du > oth.du;
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> b[i] >> p[i];
power[b[i]].push_back(p[i]);
}
fill(begin(d), end(d), inf);
d[b[0]] = 0;
priority_queue<kek> pq;
pq.push({b[0], 0});
while (!pq.empty()) {
auto [u, du] = pq.top(); pq.pop();
if (d[u] != du) continue;
// if (u == b[1]) {
// cout << du;
// return 0;
// }
//
// cerr << "@" << u << '\n';
for (auto& P : power[u]) {
for (ll v = u + P, w = 1; v < n; v += P, w++) {
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
pq.push({v, d[v]});
}
}
for (ll v = u - P, w = 1; v >= 0; v -= P, w++) {
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
pq.push({v, d[v]});
// cerr << u << ' ' << v << '\n';
}
}
}
}
cout << (d[b[1]] == inf ? -1 : d[b[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... |