#include <bits/stdc++.h>
using namespace std;
const int O = 3e4 + 5;
const int N = 2e3 + 5;
const int inf = 1e9;
int n, m, b[O], p[O], d[O];
vector <pair <int, int>> g[O];
vector <int> a[O];
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++ i){
cin >> b[i] >> p[i];
a[b[i]].push_back(p[i]);
}
for (int i = 0; i < n; ++ i){
sort(a[i].begin(), a[i].end());
a[i].resize(unique(a[i].begin(), a[i].end()) - a[i].begin());
for (int j : a[i]){
if (j == 0) continue;
for (int z = i % j; z < n; z += j){
if (z != i){
g[i].push_back({z, abs(i - z) / j});
}
}
}
}
for (int i = 0; i < n; ++ i) d[i] = inf;
priority_queue <pair <int, int>> q;
q.push({0, b[1]}); d[b[1]] = 0;
while (q.size()){
int u = q.top().second;
int du = -q.top().first;
q.pop();
if (d[u] != du) continue;
for (auto i : g[u]){
int v = i.first;
int w = i.second;
if (d[v] > d[u] + w){
d[v] = d[u] + w;
q.push({-d[v], v});
}
}
}
if (d[b[2]] >= 1e9) d[b[2]] = -1;
cout << d[b[2]];
}
Compilation message
skyscraper.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1612 KB |
Output is correct |
2 |
Correct |
1 ms |
1612 KB |
Output is correct |
3 |
Correct |
1 ms |
1612 KB |
Output is correct |
4 |
Correct |
1 ms |
1612 KB |
Output is correct |
5 |
Correct |
1 ms |
1612 KB |
Output is correct |
6 |
Correct |
1 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1612 KB |
Output is correct |
2 |
Correct |
1 ms |
1612 KB |
Output is correct |
3 |
Correct |
1 ms |
1612 KB |
Output is correct |
4 |
Correct |
1 ms |
1612 KB |
Output is correct |
5 |
Correct |
1 ms |
1612 KB |
Output is correct |
6 |
Correct |
1 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1612 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
1 ms |
1612 KB |
Output is correct |
10 |
Correct |
1 ms |
1740 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1740 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1740 KB |
Output is correct |
15 |
Correct |
1 ms |
1740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1612 KB |
Output is correct |
2 |
Correct |
1 ms |
1612 KB |
Output is correct |
3 |
Correct |
1 ms |
1612 KB |
Output is correct |
4 |
Correct |
1 ms |
1740 KB |
Output is correct |
5 |
Correct |
1 ms |
1612 KB |
Output is correct |
6 |
Correct |
1 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1612 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
1 ms |
1740 KB |
Output is correct |
10 |
Correct |
1 ms |
1740 KB |
Output is correct |
11 |
Correct |
2 ms |
1740 KB |
Output is correct |
12 |
Correct |
1 ms |
1740 KB |
Output is correct |
13 |
Correct |
1 ms |
1740 KB |
Output is correct |
14 |
Correct |
1 ms |
1740 KB |
Output is correct |
15 |
Correct |
2 ms |
1740 KB |
Output is correct |
16 |
Correct |
1 ms |
1740 KB |
Output is correct |
17 |
Correct |
2 ms |
1996 KB |
Output is correct |
18 |
Correct |
1 ms |
1740 KB |
Output is correct |
19 |
Correct |
1 ms |
1740 KB |
Output is correct |
20 |
Correct |
67 ms |
33880 KB |
Output is correct |
21 |
Correct |
1 ms |
1740 KB |
Output is correct |
22 |
Correct |
1 ms |
1740 KB |
Output is correct |
23 |
Correct |
2 ms |
1740 KB |
Output is correct |
24 |
Correct |
4 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
2 ms |
1888 KB |
Output is correct |
27 |
Correct |
3 ms |
1740 KB |
Output is correct |
28 |
Correct |
3 ms |
1996 KB |
Output is correct |
29 |
Correct |
3 ms |
2508 KB |
Output is correct |
30 |
Correct |
2 ms |
1996 KB |
Output is correct |
31 |
Correct |
3 ms |
2124 KB |
Output is correct |
32 |
Correct |
3 ms |
1972 KB |
Output is correct |
33 |
Correct |
5 ms |
3020 KB |
Output is correct |
34 |
Correct |
5 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1740 KB |
Output is correct |
2 |
Correct |
2 ms |
1612 KB |
Output is correct |
3 |
Correct |
1 ms |
1612 KB |
Output is correct |
4 |
Correct |
1 ms |
1668 KB |
Output is correct |
5 |
Correct |
2 ms |
1612 KB |
Output is correct |
6 |
Correct |
2 ms |
1612 KB |
Output is correct |
7 |
Correct |
2 ms |
1696 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
1 ms |
1612 KB |
Output is correct |
10 |
Correct |
1 ms |
1740 KB |
Output is correct |
11 |
Correct |
2 ms |
1740 KB |
Output is correct |
12 |
Correct |
2 ms |
1740 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1740 KB |
Output is correct |
15 |
Correct |
1 ms |
1740 KB |
Output is correct |
16 |
Correct |
1 ms |
1740 KB |
Output is correct |
17 |
Correct |
2 ms |
1996 KB |
Output is correct |
18 |
Correct |
1 ms |
1740 KB |
Output is correct |
19 |
Correct |
1 ms |
1740 KB |
Output is correct |
20 |
Correct |
68 ms |
33852 KB |
Output is correct |
21 |
Correct |
1 ms |
1740 KB |
Output is correct |
22 |
Correct |
2 ms |
1740 KB |
Output is correct |
23 |
Correct |
2 ms |
1740 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
2 ms |
1868 KB |
Output is correct |
27 |
Correct |
2 ms |
1740 KB |
Output is correct |
28 |
Correct |
2 ms |
1996 KB |
Output is correct |
29 |
Correct |
4 ms |
2508 KB |
Output is correct |
30 |
Correct |
3 ms |
1996 KB |
Output is correct |
31 |
Correct |
2 ms |
2124 KB |
Output is correct |
32 |
Correct |
2 ms |
1996 KB |
Output is correct |
33 |
Correct |
5 ms |
3028 KB |
Output is correct |
34 |
Correct |
5 ms |
3020 KB |
Output is correct |
35 |
Correct |
15 ms |
3616 KB |
Output is correct |
36 |
Correct |
3 ms |
1996 KB |
Output is correct |
37 |
Correct |
11 ms |
5200 KB |
Output is correct |
38 |
Correct |
13 ms |
4632 KB |
Output is correct |
39 |
Correct |
13 ms |
4820 KB |
Output is correct |
40 |
Correct |
13 ms |
4668 KB |
Output is correct |
41 |
Correct |
12 ms |
4556 KB |
Output is correct |
42 |
Correct |
7 ms |
2380 KB |
Output is correct |
43 |
Correct |
6 ms |
2384 KB |
Output is correct |
44 |
Correct |
70 ms |
34376 KB |
Output is correct |
45 |
Correct |
16 ms |
6736 KB |
Output is correct |
46 |
Correct |
21 ms |
6708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1612 KB |
Output is correct |
2 |
Correct |
1 ms |
1612 KB |
Output is correct |
3 |
Correct |
1 ms |
1612 KB |
Output is correct |
4 |
Correct |
1 ms |
1612 KB |
Output is correct |
5 |
Correct |
1 ms |
1612 KB |
Output is correct |
6 |
Correct |
1 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1612 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
1 ms |
1612 KB |
Output is correct |
10 |
Correct |
1 ms |
1740 KB |
Output is correct |
11 |
Correct |
3 ms |
1740 KB |
Output is correct |
12 |
Correct |
2 ms |
1740 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
1 ms |
1740 KB |
Output is correct |
15 |
Correct |
2 ms |
1744 KB |
Output is correct |
16 |
Correct |
1 ms |
1740 KB |
Output is correct |
17 |
Correct |
3 ms |
1996 KB |
Output is correct |
18 |
Correct |
2 ms |
1740 KB |
Output is correct |
19 |
Correct |
1 ms |
1740 KB |
Output is correct |
20 |
Correct |
64 ms |
33876 KB |
Output is correct |
21 |
Correct |
1 ms |
1740 KB |
Output is correct |
22 |
Correct |
2 ms |
1740 KB |
Output is correct |
23 |
Correct |
2 ms |
1740 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
3 ms |
1868 KB |
Output is correct |
27 |
Correct |
2 ms |
1868 KB |
Output is correct |
28 |
Correct |
2 ms |
1996 KB |
Output is correct |
29 |
Correct |
3 ms |
2508 KB |
Output is correct |
30 |
Correct |
2 ms |
1996 KB |
Output is correct |
31 |
Correct |
3 ms |
2124 KB |
Output is correct |
32 |
Correct |
2 ms |
1996 KB |
Output is correct |
33 |
Correct |
5 ms |
3020 KB |
Output is correct |
34 |
Correct |
5 ms |
3148 KB |
Output is correct |
35 |
Correct |
10 ms |
3588 KB |
Output is correct |
36 |
Correct |
4 ms |
2056 KB |
Output is correct |
37 |
Correct |
12 ms |
5200 KB |
Output is correct |
38 |
Correct |
13 ms |
4564 KB |
Output is correct |
39 |
Correct |
17 ms |
4824 KB |
Output is correct |
40 |
Correct |
13 ms |
4632 KB |
Output is correct |
41 |
Correct |
13 ms |
4520 KB |
Output is correct |
42 |
Correct |
6 ms |
2392 KB |
Output is correct |
43 |
Correct |
6 ms |
2396 KB |
Output is correct |
44 |
Correct |
71 ms |
34368 KB |
Output is correct |
45 |
Correct |
16 ms |
6736 KB |
Output is correct |
46 |
Correct |
17 ms |
6720 KB |
Output is correct |
47 |
Correct |
37 ms |
13692 KB |
Output is correct |
48 |
Correct |
18 ms |
5068 KB |
Output is correct |
49 |
Correct |
12 ms |
4184 KB |
Output is correct |
50 |
Correct |
12 ms |
3920 KB |
Output is correct |
51 |
Correct |
37 ms |
7736 KB |
Output is correct |
52 |
Correct |
36 ms |
7888 KB |
Output is correct |
53 |
Correct |
17 ms |
4572 KB |
Output is correct |
54 |
Correct |
3 ms |
2244 KB |
Output is correct |
55 |
Correct |
4 ms |
2764 KB |
Output is correct |
56 |
Runtime error |
516 ms |
262148 KB |
Execution killed with signal 9 |
57 |
Halted |
0 ms |
0 KB |
- |