이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
using namespace std;
const int INF = 1e9;
const int MAXN = 30000;
vector <int> arr[MAXN + 1];
map < pair <int, int>, bool > mp;
struct Data {
int dst, nod;
bool operator <(const Data &other) const {
return dst > other.dst;
}
};
priority_queue < Data > pq;
bool vis[MAXN + 1];
int dist[MAXN + 1];
int main() {
//ifstream cin("C.in");
//ofstream cout("C.out");
int i, n, m;
ios::sync_with_stdio(false);
cin >> n >> m;
int nod1, nod2;
for(i = 0; i < m; i++) {
int nod, jump;
cin >> nod >> jump;
if(mp[{nod, jump}] == 1) {
continue;
}
mp[{nod, jump}] = 1;
arr[nod].push_back(jump);
if(i == 0) {
pq.push({0, nod});
nod1 = nod;
}
if(i == 1) {
nod2 = nod;
}
}
for(i = 0; i < n; i++) {
dist[i] = INF;
}
dist[nod1] = 0;
while(!pq.empty()) {
int nod = pq.top().nod;
int dst = pq.top().dst;
pq.pop();
if(vis[nod]) {
continue;
}
if(nod == nod2) {
cout << dst;
return 0;
}
vis[nod] = 1;
for(auto it : arr[nod]) {
int aux = nod - it;
int cst = 1;
while(aux >= 0) {
if(dist[aux] > dst + cst) {
dist[aux] = dst + cst;
pq.push({dist[aux], aux});
}
aux -= it;
cst++;
}
aux = nod + it;
cst = 1;
while(aux < n) {
if(dist[aux] > dst + cst) {
dist[aux] = dst + cst;
pq.push({dist[aux], aux});
}
aux += it;
cst++;
}
}
}
//cin.close();
//cout.close();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:9: warning: 'nod2' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(nod == nod2) {
^~
skyscraper.cpp:50:16: warning: 'nod1' may be used uninitialized in this function [-Wmaybe-uninitialized]
dist[nod1] = 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... |