# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037848 | KasymK | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 12 ms | 604 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;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
// const int INF = 1e9;
const int N = 2e3+5;
const ll INF = (ll)1e18;
int n, m;
int b[N], p[N];
ll dist[N];
priority_queue<pair<ll, int>> pq;
ll solve(){
for(int i = 0; i < m; ++i)
dist[i] = INF;
dist[0] = 0;
pq.push({0, 0});
while (!pq.empty()){
auto x = pq.top();
pq.pop();
if (-x.ff > dist[x.ss])
continue;
if (x.ss == 1)
return -x.ff;
for(int i = 0; i < m; ++i)
if (abs(b[x.ss]-b[i])%p[x.ss] == 0){
int w = abs(b[x.ss] - b[i])/p[x.ss];
if (dist[i] > dist[x.ss]+w){
dist[i] = dist[x.ss]+w;
pq.push({-dist[i], i});
}
}
}
return -1;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0; i < m; ++i)
scanf("%d%d", &b[i], &p[i]);
ll answer = solve();
printf("%lld\n", answer);
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... |