# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45955 | 2018-04-16T14:35:40 Z | Just_Solve_The_Problem | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 286 ms | 3512 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define ll long long #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() #define ok puts("ok"); #define whatis(x) cerr << #x << " = " << x << endl; #define pause system("pause"); const int N = (int)3e4 + 7; const int inf = (int)1e9 + 7; vector < int > gr[N]; int n, m; int dist[N]; int bb[N]; int bfs() { set < pii > s; memset(dist, 63, sizeof dist); s.insert(mk(0, bb[1])); dist[bb[1]] = 0; while (!s.empty()) { pii v = *s.begin(); s.erase(s.begin()); if (v.sc == bb[2]) return v.fr; for (int i = 0; i < sz(gr[v.sc]); i++) { if (i < sz(gr[v.sc]) - 1 && gr[v.sc][i] == gr[v.sc][i + 1]) continue; int d = gr[v.sc][i]; for (int j = v.sc + d, k = 1; j <= n; j += d, k++) { if (v.fr + k < dist[j]) { s.erase(mk(dist[j], j)); dist[j] = v.fr + k; s.insert(mk(dist[j], j)); } if (binary_search(all(gr[j]), d)) break; } for (int j = v.sc - d, k = 1; j >= 1; j -= d, k++) { if (v.fr + k < dist[j]) { s.erase(mk(dist[j], j)); dist[j] = v.fr + k; s.insert(mk(dist[j], j)); } if (binary_search(all(gr[j]), d)) break; } } } return -1; } main() { scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { int a, b; scanf("%d %d", &a, &b); a++; bb[i] = a; gr[a].pb(b); } for (int i = 1; i <= n; i++) { sort(all(gr[i])); } printf("%d", bfs()); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1144 KB | Output is correct |
2 | Correct | 2 ms | 1144 KB | Output is correct |
3 | Correct | 2 ms | 1196 KB | Output is correct |
4 | Correct | 2 ms | 1248 KB | Output is correct |
5 | Correct | 2 ms | 1256 KB | Output is correct |
6 | Correct | 2 ms | 1456 KB | Output is correct |
7 | Correct | 2 ms | 1456 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1456 KB | Output is correct |
2 | Correct | 2 ms | 1456 KB | Output is correct |
3 | Correct | 2 ms | 1456 KB | Output is correct |
4 | Correct | 2 ms | 1456 KB | Output is correct |
5 | Correct | 2 ms | 1456 KB | Output is correct |
6 | Correct | 3 ms | 1456 KB | Output is correct |
7 | Correct | 2 ms | 1456 KB | Output is correct |
8 | Correct | 2 ms | 1456 KB | Output is correct |
9 | Correct | 2 ms | 1460 KB | Output is correct |
10 | Correct | 3 ms | 1460 KB | Output is correct |
11 | Correct | 3 ms | 1460 KB | Output is correct |
12 | Correct | 3 ms | 1460 KB | Output is correct |
13 | Correct | 4 ms | 1460 KB | Output is correct |
14 | Correct | 3 ms | 1460 KB | Output is correct |
15 | Correct | 3 ms | 1460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1460 KB | Output is correct |
2 | Correct | 2 ms | 1460 KB | Output is correct |
3 | Correct | 2 ms | 1460 KB | Output is correct |
4 | Correct | 2 ms | 1460 KB | Output is correct |
5 | Correct | 2 ms | 1460 KB | Output is correct |
6 | Correct | 3 ms | 1460 KB | Output is correct |
7 | Correct | 2 ms | 1460 KB | Output is correct |
8 | Correct | 2 ms | 1460 KB | Output is correct |
9 | Correct | 2 ms | 1460 KB | Output is correct |
10 | Correct | 3 ms | 1460 KB | Output is correct |
11 | Correct | 3 ms | 1460 KB | Output is correct |
12 | Correct | 3 ms | 1460 KB | Output is correct |
13 | Correct | 3 ms | 1460 KB | Output is correct |
14 | Correct | 4 ms | 1460 KB | Output is correct |
15 | Correct | 3 ms | 1460 KB | Output is correct |
16 | Correct | 3 ms | 1460 KB | Output is correct |
17 | Correct | 4 ms | 1460 KB | Output is correct |
18 | Correct | 3 ms | 1460 KB | Output is correct |
19 | Correct | 3 ms | 1460 KB | Output is correct |
20 | Correct | 4 ms | 1460 KB | Output is correct |
21 | Correct | 3 ms | 1460 KB | Output is correct |
22 | Correct | 3 ms | 1460 KB | Output is correct |
23 | Correct | 3 ms | 1460 KB | Output is correct |
24 | Correct | 4 ms | 1544 KB | Output is correct |
25 | Correct | 4 ms | 1544 KB | Output is correct |
26 | Correct | 3 ms | 1544 KB | Output is correct |
27 | Correct | 3 ms | 1544 KB | Output is correct |
28 | Correct | 3 ms | 1544 KB | Output is correct |
29 | Correct | 7 ms | 1544 KB | Output is correct |
30 | Correct | 4 ms | 1544 KB | Output is correct |
31 | Correct | 4 ms | 1544 KB | Output is correct |
32 | Correct | 4 ms | 1544 KB | Output is correct |
33 | Correct | 9 ms | 1544 KB | Output is correct |
34 | Correct | 9 ms | 1544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1544 KB | Output is correct |
2 | Correct | 3 ms | 1544 KB | Output is correct |
3 | Correct | 2 ms | 1544 KB | Output is correct |
4 | Correct | 2 ms | 1544 KB | Output is correct |
5 | Correct | 2 ms | 1544 KB | Output is correct |
6 | Correct | 2 ms | 1544 KB | Output is correct |
7 | Correct | 2 ms | 1544 KB | Output is correct |
8 | Correct | 2 ms | 1544 KB | Output is correct |
9 | Correct | 2 ms | 1544 KB | Output is correct |
10 | Correct | 3 ms | 1544 KB | Output is correct |
11 | Correct | 3 ms | 1544 KB | Output is correct |
12 | Correct | 3 ms | 1544 KB | Output is correct |
13 | Correct | 4 ms | 1544 KB | Output is correct |
14 | Correct | 3 ms | 1544 KB | Output is correct |
15 | Correct | 3 ms | 1544 KB | Output is correct |
16 | Correct | 3 ms | 1544 KB | Output is correct |
17 | Correct | 4 ms | 1544 KB | Output is correct |
18 | Correct | 3 ms | 1544 KB | Output is correct |
19 | Correct | 3 ms | 1544 KB | Output is correct |
20 | Correct | 3 ms | 1544 KB | Output is correct |
21 | Correct | 3 ms | 1544 KB | Output is correct |
22 | Correct | 3 ms | 1544 KB | Output is correct |
23 | Correct | 3 ms | 1544 KB | Output is correct |
24 | Correct | 4 ms | 1544 KB | Output is correct |
25 | Correct | 3 ms | 1612 KB | Output is correct |
26 | Correct | 3 ms | 1612 KB | Output is correct |
27 | Correct | 3 ms | 1612 KB | Output is correct |
28 | Correct | 3 ms | 1612 KB | Output is correct |
29 | Correct | 8 ms | 1612 KB | Output is correct |
30 | Correct | 4 ms | 1612 KB | Output is correct |
31 | Correct | 5 ms | 1612 KB | Output is correct |
32 | Correct | 6 ms | 1612 KB | Output is correct |
33 | Correct | 9 ms | 1612 KB | Output is correct |
34 | Correct | 9 ms | 1612 KB | Output is correct |
35 | Correct | 14 ms | 1720 KB | Output is correct |
36 | Correct | 5 ms | 1720 KB | Output is correct |
37 | Correct | 13 ms | 1720 KB | Output is correct |
38 | Correct | 16 ms | 1788 KB | Output is correct |
39 | Correct | 11 ms | 1788 KB | Output is correct |
40 | Correct | 12 ms | 1788 KB | Output is correct |
41 | Correct | 23 ms | 1788 KB | Output is correct |
42 | Correct | 9 ms | 1792 KB | Output is correct |
43 | Correct | 9 ms | 1792 KB | Output is correct |
44 | Correct | 10 ms | 1792 KB | Output is correct |
45 | Correct | 18 ms | 1792 KB | Output is correct |
46 | Correct | 18 ms | 1792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1792 KB | Output is correct |
2 | Correct | 2 ms | 1792 KB | Output is correct |
3 | Correct | 3 ms | 1792 KB | Output is correct |
4 | Correct | 2 ms | 1792 KB | Output is correct |
5 | Correct | 3 ms | 1792 KB | Output is correct |
6 | Correct | 3 ms | 1792 KB | Output is correct |
7 | Correct | 2 ms | 1792 KB | Output is correct |
8 | Correct | 3 ms | 1792 KB | Output is correct |
9 | Correct | 3 ms | 1792 KB | Output is correct |
10 | Correct | 2 ms | 1792 KB | Output is correct |
11 | Correct | 3 ms | 1792 KB | Output is correct |
12 | Correct | 3 ms | 1792 KB | Output is correct |
13 | Correct | 3 ms | 1792 KB | Output is correct |
14 | Correct | 3 ms | 1792 KB | Output is correct |
15 | Correct | 3 ms | 1792 KB | Output is correct |
16 | Correct | 2 ms | 1792 KB | Output is correct |
17 | Correct | 4 ms | 1792 KB | Output is correct |
18 | Correct | 3 ms | 1792 KB | Output is correct |
19 | Correct | 2 ms | 1792 KB | Output is correct |
20 | Correct | 4 ms | 1792 KB | Output is correct |
21 | Correct | 3 ms | 1792 KB | Output is correct |
22 | Correct | 3 ms | 1792 KB | Output is correct |
23 | Correct | 3 ms | 1792 KB | Output is correct |
24 | Correct | 4 ms | 1792 KB | Output is correct |
25 | Correct | 3 ms | 1792 KB | Output is correct |
26 | Correct | 4 ms | 1792 KB | Output is correct |
27 | Correct | 3 ms | 1792 KB | Output is correct |
28 | Correct | 3 ms | 1792 KB | Output is correct |
29 | Correct | 7 ms | 1792 KB | Output is correct |
30 | Correct | 4 ms | 1792 KB | Output is correct |
31 | Correct | 5 ms | 1792 KB | Output is correct |
32 | Correct | 4 ms | 1792 KB | Output is correct |
33 | Correct | 9 ms | 1792 KB | Output is correct |
34 | Correct | 9 ms | 1792 KB | Output is correct |
35 | Correct | 14 ms | 1792 KB | Output is correct |
36 | Correct | 4 ms | 1792 KB | Output is correct |
37 | Correct | 13 ms | 1792 KB | Output is correct |
38 | Correct | 19 ms | 1820 KB | Output is correct |
39 | Correct | 13 ms | 1820 KB | Output is correct |
40 | Correct | 13 ms | 1820 KB | Output is correct |
41 | Correct | 14 ms | 1820 KB | Output is correct |
42 | Correct | 9 ms | 1820 KB | Output is correct |
43 | Correct | 9 ms | 1820 KB | Output is correct |
44 | Correct | 9 ms | 1820 KB | Output is correct |
45 | Correct | 18 ms | 1920 KB | Output is correct |
46 | Correct | 18 ms | 1920 KB | Output is correct |
47 | Correct | 39 ms | 2300 KB | Output is correct |
48 | Correct | 11 ms | 2300 KB | Output is correct |
49 | Correct | 11 ms | 2300 KB | Output is correct |
50 | Correct | 8 ms | 2300 KB | Output is correct |
51 | Correct | 66 ms | 3512 KB | Output is correct |
52 | Correct | 64 ms | 3512 KB | Output is correct |
53 | Correct | 22 ms | 3512 KB | Output is correct |
54 | Correct | 7 ms | 3512 KB | Output is correct |
55 | Correct | 7 ms | 3512 KB | Output is correct |
56 | Correct | 14 ms | 3512 KB | Output is correct |
57 | Correct | 9 ms | 3512 KB | Output is correct |
58 | Correct | 15 ms | 3512 KB | Output is correct |
59 | Correct | 15 ms | 3512 KB | Output is correct |
60 | Correct | 16 ms | 3512 KB | Output is correct |
61 | Correct | 16 ms | 3512 KB | Output is correct |
62 | Correct | 21 ms | 3512 KB | Output is correct |
63 | Correct | 101 ms | 3512 KB | Output is correct |
64 | Correct | 99 ms | 3512 KB | Output is correct |
65 | Correct | 135 ms | 3512 KB | Output is correct |
66 | Correct | 286 ms | 3512 KB | Output is correct |
67 | Correct | 268 ms | 3512 KB | Output is correct |