이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m, dist[30002], poz;
set<int>s[30002];
bool viz[30002];
int main()
{
cin >> n >> m;
priority_queue<pair<int, int> > q;
for (int i = 0; i < m; i++) {
int b, p;
cin >> b >> p;
if (i == 1)
poz = b;
s[b].insert(p);
if (i == 0)
q.push({0, b});
}
fill(dist + 1, dist + n + 1, 1e9);
dist[q.top().second] = 0;
while (!q.empty()) {
auto x = q.top();
q.pop();
if (x.second == poz)
break;
for (auto it : s[x.second]) {
for (int i = x.second; i <= n; i += it) {
if (dist[i] > dist[x.second] + (i - x.second) / it) {
dist[i] = dist[x.second] + (i - x.second) / it;
q.push({dist[i], i});
}
}
for (int i = x.second; i >= 1; i -= it) {
if (dist[i] > dist[x.second] + (x.second) - i / it) {
dist[i] = dist[x.second] + (x.second - i) / it;
q.push({dist[i], i});
}
}
}
}
if (dist[poz] == 1e9)
dist[poz] = -1;
cout << dist[poz];
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... |