# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48488 | 2018-05-14T13:17:40 Z | Kmcode | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 834 ms | 176180 KB |
#include "bits/stdc++.h" using namespace std; int n; int m; map<pair<int, int>, vector<int> > mp; vector<pair<int, int> > bs; vector<int> con; vector<int> dist; vector<int> g[300002]; deque<int> q; int main() { cin >> n >> m; for (int i = 0; i < n; i++)bs.push_back(make_pair(-1, -1)); for (int i = 0; i < n; i++)con.push_back(-1); for (int i = 0; i < n; i++)dist.push_back(-1); int idx = n; int star = -1; int en = -1; for (int i = 0; i < m; i++) { int b, p; scanf("%d%d", &b, &p); if (i == 0)star = b; if (i == 1)en = b; pair<int, int> base = make_pair(b%p, p); if (!mp.count(base)) { mp[base].clear(); auto &v = mp[base]; for (int pos = base.first; pos < n; pos += p) { v.push_back(idx); idx++; bs.push_back(base); con.push_back(pos); dist.push_back(-1); } } int ID = (b - base.first) / p; g[b].push_back(mp[base][ID]); } dist[star] = 0; q.push_back(star); while (!q.empty()) { int b = q.front(); q.pop_front(); if (b < n) { for (int go : g[b]) { if (dist[go] == -1) { dist[go] = dist[b]; q.push_front(go); } } } else { if (con[b] != -1) { if (dist[con[b]] == -1) { dist[con[b]] = dist[b]; q.push_front(con[b]); } } if (bs[b] == bs[b - 1]&&dist[b-1]==-1) { dist[b - 1] = dist[b] + 1; q.push_back(b - 1); } if (b + 1 < bs.size() && bs[b] == bs[b + 1] && dist[b + 1] == -1) { dist[b + 1] = dist[b] + 1; q.push_back(b + 1); } } } printf("%d\n", dist[en]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 7288 KB | Output is correct |
2 | Correct | 7 ms | 7400 KB | Output is correct |
3 | Correct | 7 ms | 7480 KB | Output is correct |
4 | Correct | 8 ms | 7620 KB | Output is correct |
5 | Correct | 7 ms | 7620 KB | Output is correct |
6 | Correct | 7 ms | 7620 KB | Output is correct |
7 | Correct | 7 ms | 7620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 7664 KB | Output is correct |
2 | Correct | 7 ms | 7692 KB | Output is correct |
3 | Correct | 7 ms | 7696 KB | Output is correct |
4 | Correct | 7 ms | 7696 KB | Output is correct |
5 | Correct | 7 ms | 7704 KB | Output is correct |
6 | Correct | 7 ms | 7704 KB | Output is correct |
7 | Correct | 7 ms | 7704 KB | Output is correct |
8 | Correct | 7 ms | 7716 KB | Output is correct |
9 | Correct | 7 ms | 7716 KB | Output is correct |
10 | Correct | 7 ms | 7852 KB | Output is correct |
11 | Correct | 9 ms | 8048 KB | Output is correct |
12 | Correct | 7 ms | 8048 KB | Output is correct |
13 | Correct | 8 ms | 8048 KB | Output is correct |
14 | Correct | 10 ms | 8048 KB | Output is correct |
15 | Correct | 9 ms | 8048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 8048 KB | Output is correct |
2 | Correct | 7 ms | 8048 KB | Output is correct |
3 | Correct | 7 ms | 8048 KB | Output is correct |
4 | Correct | 8 ms | 8048 KB | Output is correct |
5 | Correct | 7 ms | 8048 KB | Output is correct |
6 | Correct | 7 ms | 8048 KB | Output is correct |
7 | Correct | 7 ms | 8048 KB | Output is correct |
8 | Correct | 7 ms | 8048 KB | Output is correct |
9 | Correct | 7 ms | 8048 KB | Output is correct |
10 | Correct | 8 ms | 8048 KB | Output is correct |
11 | Correct | 10 ms | 8100 KB | Output is correct |
12 | Correct | 8 ms | 8100 KB | Output is correct |
13 | Correct | 8 ms | 8100 KB | Output is correct |
14 | Correct | 13 ms | 8236 KB | Output is correct |
15 | Correct | 10 ms | 8248 KB | Output is correct |
16 | Correct | 8 ms | 8248 KB | Output is correct |
17 | Correct | 10 ms | 8348 KB | Output is correct |
18 | Correct | 9 ms | 8348 KB | Output is correct |
19 | Correct | 8 ms | 8348 KB | Output is correct |
20 | Correct | 8 ms | 8348 KB | Output is correct |
21 | Correct | 9 ms | 8348 KB | Output is correct |
22 | Correct | 8 ms | 8348 KB | Output is correct |
23 | Correct | 9 ms | 8348 KB | Output is correct |
24 | Correct | 10 ms | 8508 KB | Output is correct |
25 | Correct | 10 ms | 8508 KB | Output is correct |
26 | Correct | 9 ms | 8508 KB | Output is correct |
27 | Correct | 8 ms | 8508 KB | Output is correct |
28 | Correct | 12 ms | 8756 KB | Output is correct |
29 | Correct | 12 ms | 9480 KB | Output is correct |
30 | Correct | 8 ms | 9480 KB | Output is correct |
31 | Correct | 10 ms | 9480 KB | Output is correct |
32 | Correct | 10 ms | 9480 KB | Output is correct |
33 | Correct | 16 ms | 11036 KB | Output is correct |
34 | Correct | 16 ms | 11052 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11052 KB | Output is correct |
2 | Correct | 7 ms | 11052 KB | Output is correct |
3 | Correct | 7 ms | 11052 KB | Output is correct |
4 | Correct | 7 ms | 11052 KB | Output is correct |
5 | Correct | 7 ms | 11052 KB | Output is correct |
6 | Correct | 7 ms | 11052 KB | Output is correct |
7 | Correct | 8 ms | 11052 KB | Output is correct |
8 | Correct | 7 ms | 11052 KB | Output is correct |
9 | Correct | 7 ms | 11052 KB | Output is correct |
10 | Correct | 7 ms | 11052 KB | Output is correct |
11 | Correct | 9 ms | 11052 KB | Output is correct |
12 | Correct | 7 ms | 11052 KB | Output is correct |
13 | Correct | 7 ms | 11052 KB | Output is correct |
14 | Correct | 12 ms | 11052 KB | Output is correct |
15 | Correct | 9 ms | 11052 KB | Output is correct |
16 | Correct | 8 ms | 11052 KB | Output is correct |
17 | Correct | 10 ms | 11052 KB | Output is correct |
18 | Correct | 11 ms | 11052 KB | Output is correct |
19 | Correct | 8 ms | 11052 KB | Output is correct |
20 | Correct | 8 ms | 11052 KB | Output is correct |
21 | Correct | 9 ms | 11052 KB | Output is correct |
22 | Correct | 8 ms | 11052 KB | Output is correct |
23 | Correct | 9 ms | 11052 KB | Output is correct |
24 | Correct | 10 ms | 11052 KB | Output is correct |
25 | Correct | 11 ms | 11052 KB | Output is correct |
26 | Correct | 8 ms | 11052 KB | Output is correct |
27 | Correct | 8 ms | 11052 KB | Output is correct |
28 | Correct | 11 ms | 11052 KB | Output is correct |
29 | Correct | 12 ms | 11052 KB | Output is correct |
30 | Correct | 8 ms | 11052 KB | Output is correct |
31 | Correct | 10 ms | 11052 KB | Output is correct |
32 | Correct | 10 ms | 11052 KB | Output is correct |
33 | Correct | 17 ms | 11296 KB | Output is correct |
34 | Correct | 17 ms | 11376 KB | Output is correct |
35 | Correct | 50 ms | 13568 KB | Output is correct |
36 | Correct | 14 ms | 13568 KB | Output is correct |
37 | Correct | 54 ms | 14564 KB | Output is correct |
38 | Correct | 68 ms | 15788 KB | Output is correct |
39 | Correct | 64 ms | 16036 KB | Output is correct |
40 | Correct | 63 ms | 16316 KB | Output is correct |
41 | Correct | 64 ms | 16532 KB | Output is correct |
42 | Correct | 14 ms | 16532 KB | Output is correct |
43 | Correct | 14 ms | 16532 KB | Output is correct |
44 | Correct | 14 ms | 16532 KB | Output is correct |
45 | Correct | 90 ms | 24228 KB | Output is correct |
46 | Correct | 93 ms | 24392 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 24392 KB | Output is correct |
2 | Correct | 7 ms | 24392 KB | Output is correct |
3 | Correct | 7 ms | 24392 KB | Output is correct |
4 | Correct | 7 ms | 24392 KB | Output is correct |
5 | Correct | 7 ms | 24392 KB | Output is correct |
6 | Correct | 7 ms | 24392 KB | Output is correct |
7 | Correct | 7 ms | 24392 KB | Output is correct |
8 | Correct | 7 ms | 24392 KB | Output is correct |
9 | Correct | 7 ms | 24392 KB | Output is correct |
10 | Correct | 8 ms | 24392 KB | Output is correct |
11 | Correct | 9 ms | 24392 KB | Output is correct |
12 | Correct | 7 ms | 24392 KB | Output is correct |
13 | Correct | 8 ms | 24392 KB | Output is correct |
14 | Correct | 9 ms | 24392 KB | Output is correct |
15 | Correct | 10 ms | 24392 KB | Output is correct |
16 | Correct | 8 ms | 24392 KB | Output is correct |
17 | Correct | 10 ms | 24392 KB | Output is correct |
18 | Correct | 9 ms | 24392 KB | Output is correct |
19 | Correct | 8 ms | 24392 KB | Output is correct |
20 | Correct | 8 ms | 24392 KB | Output is correct |
21 | Correct | 8 ms | 24392 KB | Output is correct |
22 | Correct | 8 ms | 24392 KB | Output is correct |
23 | Correct | 9 ms | 24392 KB | Output is correct |
24 | Correct | 11 ms | 24392 KB | Output is correct |
25 | Correct | 10 ms | 24392 KB | Output is correct |
26 | Correct | 8 ms | 24392 KB | Output is correct |
27 | Correct | 8 ms | 24392 KB | Output is correct |
28 | Correct | 11 ms | 24392 KB | Output is correct |
29 | Correct | 11 ms | 24392 KB | Output is correct |
30 | Correct | 8 ms | 24392 KB | Output is correct |
31 | Correct | 10 ms | 24392 KB | Output is correct |
32 | Correct | 9 ms | 24392 KB | Output is correct |
33 | Correct | 17 ms | 24392 KB | Output is correct |
34 | Correct | 17 ms | 24392 KB | Output is correct |
35 | Correct | 51 ms | 24392 KB | Output is correct |
36 | Correct | 14 ms | 24392 KB | Output is correct |
37 | Correct | 49 ms | 24392 KB | Output is correct |
38 | Correct | 64 ms | 24392 KB | Output is correct |
39 | Correct | 63 ms | 24392 KB | Output is correct |
40 | Correct | 63 ms | 24392 KB | Output is correct |
41 | Correct | 63 ms | 24392 KB | Output is correct |
42 | Correct | 15 ms | 24392 KB | Output is correct |
43 | Correct | 14 ms | 24392 KB | Output is correct |
44 | Correct | 14 ms | 24392 KB | Output is correct |
45 | Correct | 88 ms | 27072 KB | Output is correct |
46 | Correct | 90 ms | 27284 KB | Output is correct |
47 | Correct | 121 ms | 34524 KB | Output is correct |
48 | Correct | 51 ms | 34524 KB | Output is correct |
49 | Correct | 46 ms | 34524 KB | Output is correct |
50 | Correct | 35 ms | 34524 KB | Output is correct |
51 | Correct | 89 ms | 34524 KB | Output is correct |
52 | Correct | 92 ms | 34524 KB | Output is correct |
53 | Correct | 60 ms | 34524 KB | Output is correct |
54 | Correct | 9 ms | 34524 KB | Output is correct |
55 | Correct | 11 ms | 34524 KB | Output is correct |
56 | Correct | 21 ms | 34524 KB | Output is correct |
57 | Correct | 38 ms | 34524 KB | Output is correct |
58 | Correct | 16 ms | 34524 KB | Output is correct |
59 | Correct | 19 ms | 34524 KB | Output is correct |
60 | Correct | 22 ms | 34524 KB | Output is correct |
61 | Correct | 24 ms | 34524 KB | Output is correct |
62 | Correct | 86 ms | 34524 KB | Output is correct |
63 | Correct | 288 ms | 86112 KB | Output is correct |
64 | Correct | 338 ms | 94524 KB | Output is correct |
65 | Correct | 473 ms | 114252 KB | Output is correct |
66 | Correct | 834 ms | 176108 KB | Output is correct |
67 | Correct | 828 ms | 176180 KB | Output is correct |