# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32898 | 2017-10-17T00:34:01 Z | minimario | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1000 ms | 252612 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; #define f first #define s second const int MAX = 30005; const int SQRT = 90; const int INF = 1000000000; int p[MAX], len[MAX]; // position, length vector<pair<int, int> > g[MAX*SQRT+SQRT]; vector<int> powers[MAX]; // powers of doges at a given position int dist[MAX*SQRT+SQRT]; priority_queue<pair<int, int> > pq; int xd = 0; void dijk(int i) { dist[i] = 0; //cout << i << " " << j << " " << 0 << endl; pq.push({0, i}); while (!pq.empty()) { xd += 1; auto top = pq.top(); pq.pop(); int d = -top.f; int loc = top.s; if (d > dist[loc]) { continue; } //cout << loc.f << " " << loc.s << endl; for (auto i : g[loc]) { //cout << i.f.f << " " << i.f.s << endl; int d_new = (d + i.s); if (d_new < dist[i.f]) { dist[i.f] = d_new; //cout << "came from: " << loc.f << " " << loc.s << endl; //cout << i.f.f << " " << i.f.s << " " << d_new << endl; pq.push({-d_new, i.f}); } } } } int main() { //freopen("a.in", "r", stdin); //freopen("a.out", "w", stdout); for (int i=0; i<MAX; i++) { for (int j=0; j<SQRT; j++) { dist[i*SQRT+j] = INF; } } int n, m; scanf("%d %d", &n, &m); for (int i=0; i<m; i++) { scanf("%d %d", &p[i], &len[i]); powers[p[i]].push_back(len[i]); } for (int i=0; i<n; i++) { for (int j=1; j<SQRT; j++) { g[i*SQRT+j].push_back({i*SQRT, 0}); } for (int j : powers[i]) { if (j < SQRT) { g[i*SQRT].push_back({i*SQRT+j, 0}); } } } for (int i=0; i<m; i++) { if (len[i] > SQRT) { for (int j=p[i]+len[i]; j<n; j+=len[i]) { g[p[i]*SQRT].push_back({j*SQRT, (j-p[i])/len[i]}); } for (int j=p[i]-len[i]; j>=0; j-=len[i]) { g[p[i]*SQRT].push_back({j*SQRT, (p[i]-j)/len[i]}); } } } for (int i=0; i<n; i++) { for (int j=1; j<SQRT; j++) { if (i-j >= 0) { g[i*SQRT+j].push_back({(i-j)*SQRT+j, 1}); } if (i+j < n) { g[i*SQRT+j].push_back({(i+j)*SQRT+j, 1}); } } } /* int ct = 0; for (int i=0; i<MAX; i++) { for (int j=0; j<SQRT; j++) { ct += g[i][j].size(); } } cout << ct << endl; */ dijk(p[0]*SQRT); if (dist[p[1]*SQRT] == INF) { printf("%d\n", -1); } else { printf("%d\n", dist[p[1]*SQRT]); } //cout << xd << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 76800 KB | Output is correct |
2 | Correct | 23 ms | 76800 KB | Output is correct |
3 | Correct | 33 ms | 76800 KB | Output is correct |
4 | Correct | 23 ms | 76800 KB | Output is correct |
5 | Correct | 26 ms | 76800 KB | Output is correct |
6 | Correct | 19 ms | 76800 KB | Output is correct |
7 | Correct | 23 ms | 76800 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 76800 KB | Output is correct |
2 | Correct | 36 ms | 76800 KB | Output is correct |
3 | Correct | 19 ms | 76800 KB | Output is correct |
4 | Correct | 23 ms | 76800 KB | Output is correct |
5 | Correct | 19 ms | 76800 KB | Output is correct |
6 | Correct | 23 ms | 76800 KB | Output is correct |
7 | Correct | 23 ms | 76800 KB | Output is correct |
8 | Correct | 19 ms | 76932 KB | Output is correct |
9 | Correct | 19 ms | 77064 KB | Output is correct |
10 | Correct | 26 ms | 77196 KB | Output is correct |
11 | Correct | 19 ms | 77196 KB | Output is correct |
12 | Correct | 16 ms | 77196 KB | Output is correct |
13 | Correct | 16 ms | 77196 KB | Output is correct |
14 | Correct | 16 ms | 77196 KB | Output is correct |
15 | Correct | 29 ms | 77196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 76800 KB | Output is correct |
2 | Correct | 16 ms | 76800 KB | Output is correct |
3 | Correct | 13 ms | 76800 KB | Output is correct |
4 | Correct | 19 ms | 76800 KB | Output is correct |
5 | Correct | 23 ms | 76800 KB | Output is correct |
6 | Correct | 19 ms | 76800 KB | Output is correct |
7 | Correct | 23 ms | 76800 KB | Output is correct |
8 | Correct | 26 ms | 76932 KB | Output is correct |
9 | Correct | 16 ms | 77064 KB | Output is correct |
10 | Correct | 19 ms | 77196 KB | Output is correct |
11 | Correct | 23 ms | 77196 KB | Output is correct |
12 | Correct | 19 ms | 77196 KB | Output is correct |
13 | Correct | 36 ms | 77196 KB | Output is correct |
14 | Correct | 29 ms | 77196 KB | Output is correct |
15 | Correct | 13 ms | 77196 KB | Output is correct |
16 | Correct | 29 ms | 77592 KB | Output is correct |
17 | Correct | 39 ms | 79972 KB | Output is correct |
18 | Correct | 46 ms | 84060 KB | Output is correct |
19 | Correct | 49 ms | 85116 KB | Output is correct |
20 | Correct | 59 ms | 85248 KB | Output is correct |
21 | Correct | 19 ms | 78384 KB | Output is correct |
22 | Correct | 43 ms | 84192 KB | Output is correct |
23 | Correct | 36 ms | 83532 KB | Output is correct |
24 | Correct | 56 ms | 84856 KB | Output is correct |
25 | Correct | 63 ms | 85248 KB | Output is correct |
26 | Correct | 53 ms | 85116 KB | Output is correct |
27 | Correct | 36 ms | 85116 KB | Output is correct |
28 | Correct | 59 ms | 85248 KB | Output is correct |
29 | Correct | 69 ms | 85116 KB | Output is correct |
30 | Correct | 59 ms | 85116 KB | Output is correct |
31 | Correct | 49 ms | 85116 KB | Output is correct |
32 | Correct | 49 ms | 85116 KB | Output is correct |
33 | Correct | 89 ms | 85116 KB | Output is correct |
34 | Correct | 76 ms | 85116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 76800 KB | Output is correct |
2 | Correct | 26 ms | 76800 KB | Output is correct |
3 | Correct | 16 ms | 76800 KB | Output is correct |
4 | Correct | 29 ms | 76800 KB | Output is correct |
5 | Correct | 16 ms | 76800 KB | Output is correct |
6 | Correct | 13 ms | 76800 KB | Output is correct |
7 | Correct | 23 ms | 76800 KB | Output is correct |
8 | Correct | 13 ms | 76932 KB | Output is correct |
9 | Correct | 26 ms | 77064 KB | Output is correct |
10 | Correct | 16 ms | 77196 KB | Output is correct |
11 | Correct | 23 ms | 77196 KB | Output is correct |
12 | Correct | 19 ms | 77196 KB | Output is correct |
13 | Correct | 26 ms | 77196 KB | Output is correct |
14 | Correct | 23 ms | 77196 KB | Output is correct |
15 | Correct | 23 ms | 77196 KB | Output is correct |
16 | Correct | 29 ms | 77592 KB | Output is correct |
17 | Correct | 26 ms | 79972 KB | Output is correct |
18 | Correct | 39 ms | 84060 KB | Output is correct |
19 | Correct | 49 ms | 85116 KB | Output is correct |
20 | Correct | 53 ms | 85248 KB | Output is correct |
21 | Correct | 33 ms | 78384 KB | Output is correct |
22 | Correct | 29 ms | 84192 KB | Output is correct |
23 | Correct | 49 ms | 83532 KB | Output is correct |
24 | Correct | 46 ms | 84856 KB | Output is correct |
25 | Correct | 46 ms | 85248 KB | Output is correct |
26 | Correct | 63 ms | 85116 KB | Output is correct |
27 | Correct | 59 ms | 85116 KB | Output is correct |
28 | Correct | 56 ms | 85248 KB | Output is correct |
29 | Correct | 59 ms | 85116 KB | Output is correct |
30 | Correct | 49 ms | 85116 KB | Output is correct |
31 | Correct | 69 ms | 85116 KB | Output is correct |
32 | Correct | 56 ms | 85116 KB | Output is correct |
33 | Correct | 83 ms | 85116 KB | Output is correct |
34 | Correct | 93 ms | 85116 KB | Output is correct |
35 | Correct | 49 ms | 83404 KB | Output is correct |
36 | Correct | 49 ms | 81420 KB | Output is correct |
37 | Correct | 83 ms | 85908 KB | Output is correct |
38 | Correct | 109 ms | 86172 KB | Output is correct |
39 | Correct | 89 ms | 86172 KB | Output is correct |
40 | Correct | 99 ms | 86172 KB | Output is correct |
41 | Correct | 73 ms | 86172 KB | Output is correct |
42 | Correct | 56 ms | 85604 KB | Output is correct |
43 | Correct | 56 ms | 85440 KB | Output is correct |
44 | Correct | 53 ms | 85724 KB | Output is correct |
45 | Correct | 119 ms | 88036 KB | Output is correct |
46 | Correct | 96 ms | 88016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 76800 KB | Output is correct |
2 | Correct | 16 ms | 76800 KB | Output is correct |
3 | Correct | 16 ms | 76800 KB | Output is correct |
4 | Correct | 19 ms | 76800 KB | Output is correct |
5 | Correct | 26 ms | 76800 KB | Output is correct |
6 | Correct | 19 ms | 76800 KB | Output is correct |
7 | Correct | 23 ms | 76800 KB | Output is correct |
8 | Correct | 29 ms | 76932 KB | Output is correct |
9 | Correct | 13 ms | 77064 KB | Output is correct |
10 | Correct | 19 ms | 77196 KB | Output is correct |
11 | Correct | 33 ms | 77196 KB | Output is correct |
12 | Correct | 19 ms | 77196 KB | Output is correct |
13 | Correct | 23 ms | 77196 KB | Output is correct |
14 | Correct | 23 ms | 77196 KB | Output is correct |
15 | Correct | 26 ms | 77196 KB | Output is correct |
16 | Correct | 26 ms | 77592 KB | Output is correct |
17 | Correct | 26 ms | 79972 KB | Output is correct |
18 | Correct | 46 ms | 84060 KB | Output is correct |
19 | Correct | 49 ms | 85116 KB | Output is correct |
20 | Correct | 43 ms | 85248 KB | Output is correct |
21 | Correct | 26 ms | 78384 KB | Output is correct |
22 | Correct | 43 ms | 84192 KB | Output is correct |
23 | Correct | 53 ms | 83532 KB | Output is correct |
24 | Correct | 43 ms | 84856 KB | Output is correct |
25 | Correct | 43 ms | 85248 KB | Output is correct |
26 | Correct | 59 ms | 85116 KB | Output is correct |
27 | Correct | 59 ms | 85116 KB | Output is correct |
28 | Correct | 49 ms | 85248 KB | Output is correct |
29 | Correct | 56 ms | 85116 KB | Output is correct |
30 | Correct | 53 ms | 85116 KB | Output is correct |
31 | Correct | 49 ms | 85116 KB | Output is correct |
32 | Correct | 49 ms | 85116 KB | Output is correct |
33 | Correct | 66 ms | 85116 KB | Output is correct |
34 | Correct | 69 ms | 85116 KB | Output is correct |
35 | Correct | 69 ms | 83404 KB | Output is correct |
36 | Correct | 36 ms | 81420 KB | Output is correct |
37 | Correct | 76 ms | 85908 KB | Output is correct |
38 | Correct | 69 ms | 86172 KB | Output is correct |
39 | Correct | 79 ms | 86172 KB | Output is correct |
40 | Correct | 76 ms | 86172 KB | Output is correct |
41 | Correct | 86 ms | 86172 KB | Output is correct |
42 | Correct | 49 ms | 85604 KB | Output is correct |
43 | Correct | 46 ms | 85440 KB | Output is correct |
44 | Correct | 63 ms | 85724 KB | Output is correct |
45 | Correct | 103 ms | 88036 KB | Output is correct |
46 | Correct | 119 ms | 88016 KB | Output is correct |
47 | Correct | 436 ms | 133556 KB | Output is correct |
48 | Correct | 356 ms | 175408 KB | Output is correct |
49 | Correct | 373 ms | 184116 KB | Output is correct |
50 | Correct | 399 ms | 194544 KB | Output is correct |
51 | Correct | 633 ms | 204836 KB | Output is correct |
52 | Correct | 663 ms | 204832 KB | Output is correct |
53 | Correct | 523 ms | 202728 KB | Output is correct |
54 | Correct | 466 ms | 201940 KB | Output is correct |
55 | Correct | 496 ms | 201936 KB | Output is correct |
56 | Correct | 513 ms | 204312 KB | Output is correct |
57 | Correct | 773 ms | 202200 KB | Output is correct |
58 | Correct | 563 ms | 202412 KB | Output is correct |
59 | Correct | 523 ms | 202296 KB | Output is correct |
60 | Correct | 526 ms | 202904 KB | Output is correct |
61 | Correct | 516 ms | 202628 KB | Output is correct |
62 | Correct | 659 ms | 205636 KB | Output is correct |
63 | Correct | 633 ms | 227004 KB | Output is correct |
64 | Correct | 636 ms | 237352 KB | Output is correct |
65 | Correct | 663 ms | 252612 KB | Output is correct |
66 | Execution timed out | 1000 ms | 248764 KB | Execution timed out |
67 | Halted | 0 ms | 0 KB | - |