# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
668154 | mhn2 | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1101 ms | 68828 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>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define endl '\n'
using namespace std;
const int N = 3e4+5;
int b[N], p[N];
ll d[N];
vector<pii> adj[N];
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> b[i] >> p[i];
d[i] = -1;
}
for (int i = 1; i <= m; i++)
for (int j = 1; j <= m; j++)
if (i != j && abs(b[i]-b[j]) % p[i] == 0)
adj[i].pb(make_pair(j, abs(b[i]-b[j]) / p[i]));
set<pll> q;
q.insert(make_pair(0, 1));
while (q.size()) {
auto it = --q.end();
ll v = it->S, w = -it->F;
q.erase(it);
if (d[v] != -1)
continue;
d[v] = w;
for (int i = 0; i < adj[v].size(); i++)
q.insert(make_pair(-w-adj[v][i].S, adj[v][i].F));
}
cout << d[2];
}
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... |