| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 25653 | gabrielsimoes | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1000 ms | 3648 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;
const int MAXN = 3e4+10;
const ll INF = ll(MAXN)*ll(MAXN)*ll(MAXN);
int N, M, X, Y;
vector<int> v[MAXN];
bool ok[MAXN];
ll d[MAXN];
void dijkstra() {
memset(d, -1, sizeof(d));
d[X] = 0;
while (true) {
int cur = -1;
for (int i = 0; i < N; i++)
if (d[i] != -1 && !ok[i] && (cur == -1 || d[i] < d[cur]))
cur = i;
if (cur == -1) return;
ok[cur] = true;
for (int dx : v[cur]) {
int cnt = (N - cur)/dx;
int i = cur + dx*cnt;
while (i >= 0) {
if (d[i] == -1 || d[cur] + abs(cnt) < d[i])
d[i] = d[cur] + abs(cnt);
i -= dx; cnt--;
}
}
}
}
int main()
{
scanf("%d %d", &N, &M);
for (int i = 0,a,b; i < M; i++) {
scanf("%d %d", &a, &b);
if (i == 0) X = a;
else if (i == 1) Y = a;
if (b != 0) v[a].push_back(b);
}
for (int i = 0; i < N; i++)
sort(v[i].begin(), v[i].end()),
v[i].resize(unique(v[i].begin(), v[i].end()) - v[i].begin());
dijkstra();
printf("%lld\n", d[Y]);
}
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... | ||||
