이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 1;
const int OOO = 1;
using namespace std;
struct edge {
int to, w;
edge(int tt, int ww) {
to = tt;
w = ww;
}
bool operator < (const edge &a) const {
return w > a.w;
}
};
int n, m;
int B[30003], P[30003];
vector<edge> g[30003];
map<pair<int, int>, vector<int>> M;
int d[30003];
vector<int> nxt[30003];
void add(vector<int> &pos, int len) {
sort(pos.begin(), pos.end());
int l, r;
for (int i = 0; i < pos.size(); i++) {
l = (i == 0 ? 0 : pos[i - 1]);
r = (i == (int)pos.size() - 1 ? n - 1 : pos[i + 1]);
for (int j = pos[i] - len; j >= l; j -= len)
g[pos[i]].push_back(edge(j, (pos[i] - j) / len));
for (int j = pos[i] + len; j <= r; j += len)
g[pos[i]].push_back(edge(j, (j - pos[i]) / len));
}
}
void dijkstra() {
for (int i = 0; i < n; i++) d[i] = -1;
/*
nxt[0].push_back(B[0]);
for (int dis = 0; dis <= n; dis++) {
for (const auto &x : nxt[dis]) {
if (d[x] != -1) continue;
d[x] = dis;
for (const auto &i : g[x])
if (dis + i.w <= n && d[i.to] == -1)
nxt[dis + i.w].push_back(i.to);
}
}
*/
priority_queue<edge> q;
q.push(edge(B[0], 0));
while (q.size()) {
edge x = q.top();
q.pop();
if (d[x.to] != -1) continue;
d[x.to] = x.w;
for (const auto &i : g[x.to])
if (d[i.to] == -1)
q.push(edge(i.to, x.w + i.w));
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> B[i] >> P[i];
for (int j = B[i] - P[i]; j >= 0; j -= P[i]) g[B[i]].push_back(edge(j, (B[i] - j) / P[i]));
for (int j = B[i] + P[i]; j <= n - 1; j += P[i]) g[B[i]].push_back(edge(j, (j - B[i]) / P[i]));
//M[{B[i] % P[i], P[i]}].push_back(B[i]);
}
//for (auto &i : M) add(i.second, i.first.second);
dijkstra();
cout << d[B[1]] << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'void add(std::vector<int>&, int)':
skyscraper.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < 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... |