# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108316 | kek | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 221 ms | 263168 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;
typedef long long ll;
typedef long double ld;
// #define int ll
#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define debug(x) cout << #x << " = " << x << endl;
const int INF = 1e9 + 666;
template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifndef LOCAL
void UseFiles(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif
void run();
signed main() {
// UseFiles("cowboys");
iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
run();
}
void run() {
int n, m;
cin >> n >> m;
vector<pii> doges(m);
swap(n, m);
for (auto &x : doges) {
cin >> x.first >> x.second;
}
vector<vector<int>> g(n, vector<int>(n, INF));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ((doges[i].first - doges[j].first) % doges[i].second == 0) {
g[i][j] = abs((doges[i].first - doges[j].first) / doges[i].second);
}
}
}
vector<int> dist(n, INF);
dist[0] = 0;
priority_queue<pii, vector<pii>, greater<pii>> q;
q.push({0, 0});
while (len(q)) {
int d, v;
tie(d, v) = q.top();
q.pop();
if (dist[v] != d) {
continue;
}
for (int i = 0; i < n; ++i) {
if (cmin(dist[i], d + g[v][i])) {
q.push({dist[i], i});
}
}
}
if (dist[1] == INF) {
cout << -1 << endl;
} else {
cout << dist[1] << endl;
}
}
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... |