이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAXN=6e4+10;
vector <pair <int,int> > v[MAXN];
priority_queue <pair <int,int> > q;
int ans[MAXN];
void dejkstra(int start) {
ans[start]=0;
q.push({0,start});
while (!q.empty()) {
int x=q.top().second;
if (-q.top().first!=ans[x]) {
q.pop();
continue;
}
q.pop();
for (auto i:v[x]) {
if (ans[i.first]==-1 || ans[i.first]>ans[x]+i.second) {
ans[i.first]=ans[x]+i.second;
q.push({-ans[i.first],i.first});
}
}
}
}
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m, beg, steps, start, ed;
cin >> n >> m;
for (int j=0;j<m;j++) {
cin >> beg >> steps;
if (j==0) start=beg;
if (j==1) ed=beg;
int br=1;
for (int i=beg+steps;i<n;i+=steps) {
v[beg].push_back({i,br});
br++;
}
br=1;
for (int i=beg-steps;i>=0;i-=steps) {
v[beg].push_back({i,br});
br++;
}
}
for (int i=0;i<n+m;i++) ans[i]=-1;
dejkstra(start);
cout << ans[ed] << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:19: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | cout << ans[ed] << endl;
| ^
skyscraper.cpp:49:13: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | dejkstra(start);
| ~~~~~~~~^~~~~~~
# | 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... |