이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
set<int> doges[30000];
vector<pair<int, int>> graph[30000];
int visited[30000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, src, dest;
cin >> n >> m;
FOR(i, 0, m) {
int b, p;
cin >> b >> p;
if (!i) src = b;
if (i == 1) dest = b;
doges[b].insert(p);
}
FOR(i, 0, n) {
for (int j : doges[i]) {
for (int k = i + j, cnt = 1; k < n; k += j, cnt++) {
graph[i].push_back({k, cnt});
if (doges[k].find(j) != doges[k].end()) break;
}
for (int k = i - j, cnt = 1; k >= 0; k -= j, cnt++) {
graph[i].push_back({k, cnt});
if (doges[k].find(j) != doges[k].end()) break;
}
}
}
priority_queue<pair<int, int>> pq;
pq.push({-1, src});
while (pq.size()) {
int dist, node;
tie(dist, node) = pq.top();
pq.pop();
if (!visited[node]) {
visited[node] = dist;
if (node == dest) return cout << -dist - 1, 0;
for (pair<int, int> i : graph[node]) pq.push({dist - i.second, i.first});
}
}
cout << -1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:44:13: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (node == dest) return cout << -dist - 1, 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... |