이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In The Name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int N = 2000 + 10;
const int M = 50000 + 10;
const ll inf = 1e18 + 10;
ll b[M], P[M], d[M];
vector < ll > vec[M];
priority_queue < pll , vector < pll > , greater < pll > > pq;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, m;
cin >> n >> m;
for (ll i = 0; i < m; i ++){
cin >> b[i] >> P[i];
vec[b[i]].pb(P[i]);
}
fill(d, d + M, inf);
d[b[0]] = 0;
pq.push(mp(0, b[0]));
while (!pq.empty()){
ll x = pq.top().Y, c = pq.top().X;
pq.pop();
if (d[x] < c)
continue;
for (ll p : vec[x]){
for (ll y = x, t = 0; y < n; y += p, t ++){
if (c + t < d[y]){
d[y] = c + t;
pq.push(mp(d[y], y));
}
}
for (ll y = x, t = 0; 0 <= y; y -= p, t ++){
if (c + t < d[y]){
d[y] = c + t;
pq.push(mp(d[y], y));
}
}
}
}
cout << (d[b[1]] >= inf ? -1 : d[b[1]]) << '\n';
return 0;
}
# | 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... |