이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 30003;
vector<pii> G[MAX];
int D[MAX];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, M, S, E;
cin >> N >> M;
map<pii, vector<int>> make;
for (int i = 0; i < M; ++i) {
int b, p;
cin >> b >> p;
if (i == 0) S = b;
if (i == 1) E = b;
make[{p, b % p}].push_back(b);
}
for (auto& [q, v] : make) {
auto [p, init] = q;
v.push_back(init);
v.push_back(init + (N - 1 - init) / p * p);
sort(v.begin(), v.end());
for (int i = 1; i + 1 < v.size(); ++i) {
int n = v[i] - p, d = 1;
while (n >= v[i - 1]) {
G[v[i]].emplace_back(n, d++);
n -= p;
}
n = v[i] + p, d = 1;
while (n <= v[i + 1]) {
G[v[i]].emplace_back(n, d++);
n += p;
}
}
}
memset(D, 0x3f, sizeof(D));
priority_queue<pii, vector<pii>, greater<pii>> PQ;
PQ.emplace(D[S] = S, S);
while (!PQ.empty()) {
auto [cd, cur] = PQ.top(); PQ.pop();
if (cd > D[cur]) continue;
if (cur == E) break;
for (auto [next, nd] : G[cur]) {
if (cd + nd >= D[next]) continue;
PQ.emplace(D[next] = cd + nd, next);
}
}
cout << (D[E] > 1E9 ? -1 : D[E]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:31:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 1; i + 1 < v.size(); ++i) {
| ~~~~~~^~~~~~~~~~
skyscraper.cpp:51:3: warning: 'E' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | if (cur == E) break;
| ^~
# | 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... |