# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25390 | 2017-06-21T21:00:40 Z | gabrielsimoes | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 3 ms | 2960 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef long long ll; const int MAXN = 3e4 + 100; const ll INF = ll(MAXN)*ll(MAXN); int N, M; vector<int> v[MAXN]; ll dp[MAXN]; ll f(int cur) { if (dp[cur] != -1) return dp[cur]; dp[cur] = INF; for (int dx : v[cur]) { int i = cur - dx*(cur/dx); do dp[cur] = min(dp[cur], f(i) + abs(cur - i)/dx); while ((i += dx) < N); } return dp[cur]; } int main() { scanf("%d %d", &N, &M); int X, Y; 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); } memset(dp, -1, sizeof(dp)); dp[Y] = 0; ll ans = f(X); printf("%lld\n", ans < INF ? ans : -1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2960 KB | Output is correct |
2 | Correct | 0 ms | 2960 KB | Output is correct |
3 | Correct | 0 ms | 2960 KB | Output is correct |
4 | Correct | 0 ms | 2960 KB | Output is correct |
5 | Correct | 0 ms | 2960 KB | Output is correct |
6 | Correct | 0 ms | 2960 KB | Output is correct |
7 | Correct | 0 ms | 2960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2960 KB | Output is correct |
2 | Correct | 0 ms | 2960 KB | Output is correct |
3 | Correct | 0 ms | 2960 KB | Output is correct |
4 | Correct | 0 ms | 2960 KB | Output is correct |
5 | Correct | 0 ms | 2960 KB | Output is correct |
6 | Correct | 0 ms | 2960 KB | Output is correct |
7 | Correct | 0 ms | 2960 KB | Output is correct |
8 | Correct | 0 ms | 2960 KB | Output is correct |
9 | Correct | 0 ms | 2960 KB | Output is correct |
10 | Correct | 0 ms | 2960 KB | Output is correct |
11 | Correct | 0 ms | 2960 KB | Output is correct |
12 | Correct | 0 ms | 2960 KB | Output is correct |
13 | Correct | 0 ms | 2960 KB | Output is correct |
14 | Correct | 0 ms | 2960 KB | Output is correct |
15 | Correct | 0 ms | 2960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2960 KB | Output is correct |
2 | Correct | 0 ms | 2960 KB | Output is correct |
3 | Correct | 0 ms | 2960 KB | Output is correct |
4 | Correct | 0 ms | 2960 KB | Output is correct |
5 | Correct | 0 ms | 2960 KB | Output is correct |
6 | Correct | 0 ms | 2960 KB | Output is correct |
7 | Correct | 0 ms | 2960 KB | Output is correct |
8 | Correct | 0 ms | 2960 KB | Output is correct |
9 | Correct | 0 ms | 2960 KB | Output is correct |
10 | Correct | 0 ms | 2960 KB | Output is correct |
11 | Correct | 0 ms | 2960 KB | Output is correct |
12 | Correct | 0 ms | 2960 KB | Output is correct |
13 | Correct | 3 ms | 2960 KB | Output is correct |
14 | Correct | 0 ms | 2960 KB | Output is correct |
15 | Correct | 0 ms | 2960 KB | Output is correct |
16 | Correct | 0 ms | 2960 KB | Output is correct |
17 | Incorrect | 0 ms | 2960 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2960 KB | Output is correct |
2 | Correct | 0 ms | 2960 KB | Output is correct |
3 | Correct | 0 ms | 2960 KB | Output is correct |
4 | Correct | 0 ms | 2960 KB | Output is correct |
5 | Correct | 0 ms | 2960 KB | Output is correct |
6 | Correct | 0 ms | 2960 KB | Output is correct |
7 | Correct | 0 ms | 2960 KB | Output is correct |
8 | Correct | 0 ms | 2960 KB | Output is correct |
9 | Correct | 0 ms | 2960 KB | Output is correct |
10 | Correct | 0 ms | 2960 KB | Output is correct |
11 | Correct | 0 ms | 2960 KB | Output is correct |
12 | Correct | 0 ms | 2960 KB | Output is correct |
13 | Correct | 0 ms | 2960 KB | Output is correct |
14 | Correct | 0 ms | 2960 KB | Output is correct |
15 | Correct | 0 ms | 2960 KB | Output is correct |
16 | Correct | 0 ms | 2960 KB | Output is correct |
17 | Incorrect | 0 ms | 2960 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2960 KB | Output is correct |
2 | Correct | 0 ms | 2960 KB | Output is correct |
3 | Correct | 0 ms | 2960 KB | Output is correct |
4 | Correct | 0 ms | 2960 KB | Output is correct |
5 | Correct | 0 ms | 2960 KB | Output is correct |
6 | Correct | 0 ms | 2960 KB | Output is correct |
7 | Correct | 0 ms | 2960 KB | Output is correct |
8 | Correct | 0 ms | 2960 KB | Output is correct |
9 | Correct | 0 ms | 2960 KB | Output is correct |
10 | Correct | 0 ms | 2960 KB | Output is correct |
11 | Correct | 0 ms | 2960 KB | Output is correct |
12 | Correct | 0 ms | 2960 KB | Output is correct |
13 | Correct | 3 ms | 2960 KB | Output is correct |
14 | Correct | 0 ms | 2960 KB | Output is correct |
15 | Correct | 0 ms | 2960 KB | Output is correct |
16 | Correct | 0 ms | 2960 KB | Output is correct |
17 | Incorrect | 0 ms | 2960 KB | Output isn't correct |
18 | Halted | 0 ms | 0 KB | - |