# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110720 | nhphuc | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 130 ms | 190836 KiB |
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>
using namespace std;
#define iii tuple<int, int, int>
const int N = 50500;
const int block = 157;
int n, m, b[N], v[N], dp[N][block + 7], ans = -1;
bool vis[N][block + 7];
vector<int> pw[N];
vector<pair<int, int>> Q[N * block + 107];
int32_t main (){
ios::sync_with_stdio(false); cin.tie(nullptr);
if (fopen("test.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j <= block + 1; ++j)
dp[i][j] = -1;
for (int i = 1; i <= m; ++i){
cin >> b[i] >> v[i];
pw[b[i]].push_back(v[i]);
if (i == 1)
Q[0].push_back({b[i], v[i]});
}
for (int D = 0; D < N * block; ++D){
for (pair<int, int> it : Q[D]){
int u = it.first;
int t = it.second;
if (dp[u][t] != -1)
continue;
if (vis[u][t])
continue;
vis[u][t] = true;
dp[u][t] = D;
if (u == b[2])
ans = min((ans == -1 ? (int)1e16 : ans), D);
if (t <= block){
if (u - t >= 0 && dp[u - t][t] == -1)
Q[D + 1].push_back({u - t, t});
if (u + t < n && dp[u + t][t] == -1)
Q[D + 1].push_back({u + t, t});
}
for (int X : pw[u]){
if (X <= block){
if (u - X >= 0 && dp[u - X][X] == -1)
Q[D + 1].push_back({u - X, X});
if (u + X < n && dp[u + X][X] == -1)
Q[D + 1].push_back({u + X, X});
} else {
for (int i = u - X; i >= 0; i -= X)
if (dp[i][block + 1] == -1)
Q[D + (u - i) / X].push_back({i, X});
for (int i = u + X; i < n; i += X)
if (dp[i][block + 1] == -1)
Q[D + (i - u) / X].push_back({i, X});
}
}
}
}
cout << ans << "\n";
}
Compilation message (stderr)
# | 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... |