This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int C = 200;
int N, M, st, ed, dist[30005][205];
vector<iii> adj[30005][205];
priority_queue<iii, vector<iii>, greater<iii> > pq;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) {
for (int j = 1; j < C; j++) {
if (i + j < N) adj[i][j].eb(i + j, j, 1);
if (i - j >= 0) adj[i][j].eb(i - j, j, 1);
dist[i][j] = 1e16;
adj[i][j].eb(i, 0, 0);
}
dist[i][0] = 1e16;
}
for (int i = 0, B, P; i < M; i++) {
cin >> B >> P;
if (P >= C) {
for (int j = B + P; j < N; j += P)
adj[B][0].eb(j, 0, (j - B) / P);
for (int j = B - P; j >= 0; j -= P)
adj[B][0].eb(j, 0, (B - j) / P);
} else {
adj[B][0].eb(B, P, 0);
}
if (i == 0) st = B;
else if (i == 1) ed = B;
}
pq.emplace(0, st, 0);
dist[st][0] = 0;
while (!pq.empty()) {
auto [d, x, y] = pq.top();
pq.pop();
if (d != dist[x][y]) continue;
if (x == ed) return cout << d << '\n', 0;
for (auto [u, v, w] : adj[x][y]) {
if (dist[u][v] > d + w) {
dist[u][v] = d + w;
pq.emplace(dist[u][v], u, v);
}
}
}
cout << "-1\n";
}
Compilation message (stderr)
skyscraper.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
33 | main() {
| ^~~~
# | 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... |