이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
};
template <typename T>
bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for(int i = 0; i < v.size(); i++) {
os << v[i] << (i + 1 == v.size() ? "\n" : " ");
}
return os;
}
template <typename T>
vector<T> make_v(size_t a) {
return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
for(auto& e : t) {
fill_v(e, v);
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
struct edge {
ll to, cost;
};
vector<vector<edge>> G(n);
vector<set<int>> st(n);
int s, g;
for(int i = 0; i < m; i++) {
int b, p;
cin >> b >> p;
if(i == 0) {
s = b;
} else if(i == 1) {
g = b;
continue;
}
int k = 0;
if(st[b].count(p)) {
continue;
}
for(int j = b + p; j < n; j += p) {
k++;
G[b].push_back({j, k});
if(st[j].count(p)) {
break;
}
}
k = 0;
for(int j = b - p; j >= 0; j -= p) {
k++;
G[b].push_back({j, k});
if(st[j].count(p)) {
break;
}
}
st[b].insert(p);
}
priority_queue<P, vector<P>, greater<P>> q;
vector<ll> d(n, LINF);
d[s] = 0;
q.push(P(0, s));
while(!q.empty()) {
int v = q.top().second;
q.pop();
for(auto e : G[v]) {
if(d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
q.push(P(d[e.to], e.to));
}
}
}
if(d[g] == LINF) {
cout << -1 << endl;
} else {
cout << d[g] << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:94:8: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
d[s] = 0;
^
skyscraper.cpp:106:11: warning: 'g' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(d[g] == LINF) {
^
# | 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... |