# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330660 | fammo | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 1095 ms | 1280 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.
#pragma GCC optimize("unroll-loops, Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
const int MAXN = 30000 + 7;
int n, m, p[MAXN], b[MAXN], dis[MAXN];
vector<int>adj[MAXN];
inline void dij(int root){
set<pair<int, int>>s;
fill(dis, dis + MAXN, LLONG_MAX/2);
dis[root] = 0;
s.insert({0, root});
for(int i = 0; i < m; i ++){
auto x = *s.begin();
int v = x.second, d = x.first;
s.erase(s.begin());
for(auto p : adj[v]){
int cnt = 1;
for(int u = v + p; u < n; u += p){
if(d + cnt < dis[u]){
s.erase({dis[u], u});
dis[u] = d + cnt;
s.insert({dis[u], u});
}
cnt ++;
}
cnt = 1;
for(int u = v - p; u > -1; u -= p){
if(d + cnt < dis[u]){
s.erase({dis[u], u});
dis[u] = d + cnt;
s.insert({dis[u], u});
}
cnt ++;
}
}
}
return;
}
int32_t main(){
//ios_base::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
//cin >> n >> m;
scanf("%lld %lld", &n, &m);
for(int i = 0; i < m; i ++){
//cin >> b[i] >> p[i];
scanf("%lld %lld", &b[i], &p[i]);
adj[b[i]].pb(p[i]);
}
dij(0);
printf("%lld\n", (dis[1] >= LLONG_MAX/2? -1ll : dis[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... |