이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <functional>
#include <algorithm>
#include <cmath>
using namespace std;
int N, M, A[30009], P[30009], dist[7400009], sz; pair<int, int>vec[2400009];
vector<int> G[30009], X[2400009];
map<pair<int, int>, int>M1; queue<int>Q;
void connect(int px, int py, int qx, int qy, int cost) {
int pos1 = lower_bound(vec, vec + sz, make_pair(px, py)) - vec;
int pos2 = lower_bound(vec, vec + sz, make_pair(qx, qy)) - vec;
X[pos1].push_back(pos2);
}
int main() {
cin >> N >> M;
for (int i = 1; i <= M; i++) {
cin >> A[i] >> P[i]; G[A[i]].push_back(P[i]);
if (M1[make_pair(A[i] % P[i], P[i])] == 0) {
M1[make_pair(A[i] % P[i], P[i])] = 1;
for (int j = A[i] % P[i]; j < N; j += P[i]) { vec[sz] = make_pair(j, P[i]); sz++; }
}
}
for (int i = 0; i < N; i++) { vec[sz] = make_pair(i, 0); sz++; }
sort(vec, vec + sz);
for (int i = 0; i < sz; i++) {
int pos = vec[i].first, state = vec[i].second;
if (state == 0) {
for (int j = 0; j < G[pos].size(); j++) {
if (pos - G[pos][j] >= 0) {
connect(pos, 0, pos - G[pos][j], G[pos][j], 1);
connect(pos, 0, pos - G[pos][j], 0, 1);
}
if (pos + G[pos][j] < N) {
connect(pos, 0, pos + G[pos][j], G[pos][j], 1);
connect(pos, 0, pos + G[pos][j], 0, 1);
}
}
}
else {
if (pos - state >= 0) {
connect(pos, state, pos - state, state, 1);
connect(pos, state, pos - state, 0, 1);
}
if (pos + state < N) {
connect(pos, state, pos + state, state, 1);
connect(pos, state, pos + state, 0, 1);
}
}
}
for (int i = 0; i < sz; i++) dist[i] = (1 << 30);
int sx = lower_bound(vec, vec + sz, make_pair(A[1], 0)) - vec;
int gx = lower_bound(vec, vec + sz, make_pair(A[2], 0)) - vec;
dist[sx] = 0; Q.push(sx);
while (!Q.empty()) {
int pos = Q.front(); Q.pop();
for (int i = 0; i < X[pos].size(); i++) {
int to = X[pos][i];
if (dist[to] > dist[pos] + 1) {
dist[to] = dist[pos] + 1;
Q.push(to);
}
}
}
int ans = dist[gx]; if (ans == (1 << 30)) ans = -1;
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < G[pos].size(); j++) {
~~^~~~~~~~~~~~~~~
skyscraper.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < X[pos].size(); i++) {
~~^~~~~~~~~~~~~~~
# | 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... |