이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 30003, inf = 1e9;
int n, m, num, ind[n0];
vector <int> rem[n0], vec[n0], b, d, out[n0];
vector <vector <int>> g;
void bfs(int x) {
deque <int> q;
q.pb(x);
for (int i = 0; i < num; i++)
d[i] = inf;
d[x] = 0;
while (!q.empty()) {
int v = q.front();
q.pop_front();
if (v < n) {
for (int i : out[v]) {
if (d[i] > d[v]) {
d[i] = d[v];
q.push_front(i);
}
}
} else {
for (int i : g[v]) {
if (i < n) {
if (d[i] > d[v]) {
d[i] = d[v];
q.push_front(i);
}
} else {
if (d[i] > d[v] + 1) {
d[i] = d[v] + 1;
q.pb(i);
}
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
cin >> n >> m;
int s, f;
for (int i = 0; i < m; i++) {
int B, P;
cin >> B >> P;
if (i == 0) s = B;
if (i == 1) f = B;
vec[P].pb(B);
rem[P].pb(B % P);
}
num = n;
for (int i = 1; i < n0; i++) {
cps(rem[i]);
for (int j : rem[i])
num += ((n - 1) - j) / i + 1;
}
b.resize(num), d.resize(num), g.resize(num);
int cur = n;
for (int i = 1; i < n0; i++) {
for (int j : rem[i]) {
for (int k = j; k < n; k += i) {
if (k > j)
g[cur].pb(cur - 1), g[cur - 1].pb(cur);
g[cur].pb(k);
ind[k] = cur++;
}
}
for (int j : vec[i])
out[j].pb(ind[j]);
}
bfs(s);
if (d[f] == inf) cout << -1;
else cout << d[f];
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:83:9: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
83 | if (d[f] == inf) cout << -1;
| ^
skyscraper.cpp:82:5: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
82 | bfs(s);
| ~~~^~~
# | 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... |