#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){
for (int j : a[i]){
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 |
2 ms |
1624 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 |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
3 ms |
1740 KB |
Output is correct |
12 |
Correct |
6 ms |
3912 KB |
Output is correct |
13 |
Correct |
5 ms |
4036 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 |
1612 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 |
1868 KB |
Output is correct |
12 |
Correct |
5 ms |
3912 KB |
Output is correct |
13 |
Correct |
5 ms |
4036 KB |
Output is correct |
14 |
Correct |
2 ms |
1740 KB |
Output is correct |
15 |
Correct |
1 ms |
1740 KB |
Output is correct |
16 |
Correct |
2 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 |
64 ms |
33860 KB |
Output is correct |
21 |
Correct |
2 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 |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
67 ms |
34708 KB |
Output is correct |
27 |
Correct |
74 ms |
34744 KB |
Output is correct |
28 |
Correct |
2 ms |
1996 KB |
Output is correct |
29 |
Correct |
3 ms |
2380 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 |
4 ms |
2892 KB |
Output is correct |
34 |
Correct |
4 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1612 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 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 |
2 ms |
1740 KB |
Output is correct |
12 |
Correct |
5 ms |
3916 KB |
Output is correct |
13 |
Correct |
5 ms |
4036 KB |
Output is correct |
14 |
Correct |
2 ms |
1740 KB |
Output is correct |
15 |
Correct |
2 ms |
1740 KB |
Output is correct |
16 |
Correct |
2 ms |
1740 KB |
Output is correct |
17 |
Correct |
2 ms |
1996 KB |
Output is correct |
18 |
Correct |
2 ms |
1740 KB |
Output is correct |
19 |
Correct |
2 ms |
1740 KB |
Output is correct |
20 |
Correct |
66 ms |
33860 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 |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
4 ms |
1868 KB |
Output is correct |
26 |
Correct |
74 ms |
34724 KB |
Output is correct |
27 |
Correct |
69 ms |
34760 KB |
Output is correct |
28 |
Correct |
2 ms |
1996 KB |
Output is correct |
29 |
Correct |
3 ms |
2380 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 |
4 ms |
3008 KB |
Output is correct |
34 |
Correct |
4 ms |
3020 KB |
Output is correct |
35 |
Correct |
10 ms |
3624 KB |
Output is correct |
36 |
Correct |
3 ms |
2000 KB |
Output is correct |
37 |
Correct |
11 ms |
5332 KB |
Output is correct |
38 |
Correct |
14 ms |
4956 KB |
Output is correct |
39 |
Correct |
17 ms |
5072 KB |
Output is correct |
40 |
Correct |
18 ms |
4968 KB |
Output is correct |
41 |
Correct |
13 ms |
4848 KB |
Output is correct |
42 |
Runtime error |
349 ms |
262148 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1740 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 |
1648 KB |
Output is correct |
11 |
Correct |
2 ms |
1740 KB |
Output is correct |
12 |
Correct |
5 ms |
3912 KB |
Output is correct |
13 |
Correct |
5 ms |
4036 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 |
2044 KB |
Output is correct |
18 |
Correct |
1 ms |
1740 KB |
Output is correct |
19 |
Correct |
1 ms |
1812 KB |
Output is correct |
20 |
Correct |
64 ms |
33824 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 |
1880 KB |
Output is correct |
25 |
Correct |
2 ms |
1880 KB |
Output is correct |
26 |
Correct |
77 ms |
34764 KB |
Output is correct |
27 |
Correct |
63 ms |
34644 KB |
Output is correct |
28 |
Correct |
2 ms |
2024 KB |
Output is correct |
29 |
Correct |
3 ms |
2380 KB |
Output is correct |
30 |
Correct |
2 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 |
4 ms |
3008 KB |
Output is correct |
34 |
Correct |
5 ms |
3020 KB |
Output is correct |
35 |
Correct |
10 ms |
3624 KB |
Output is correct |
36 |
Correct |
3 ms |
2004 KB |
Output is correct |
37 |
Correct |
12 ms |
5264 KB |
Output is correct |
38 |
Correct |
14 ms |
4848 KB |
Output is correct |
39 |
Correct |
12 ms |
5128 KB |
Output is correct |
40 |
Correct |
16 ms |
4944 KB |
Output is correct |
41 |
Correct |
13 ms |
4816 KB |
Output is correct |
42 |
Runtime error |
336 ms |
262148 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |