#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g(30005);
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m; cin >> n >> m;
int f, s;
for(int i = 0; i < m; i++) {
int x, y; cin >> x >> y;
if(i == 0) f = x;
if(i == 1) s = x;
if(y == 0) continue;
g[x].push_back(y);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> c;
vector<int> d(n, 2e9);
d[f] = 0;
c.push({0, f});
while(!c.empty()) {
int u = c.top().second, w = c.top().first;
c.pop();
if(d[u] != w) continue;
if(u == s) {
cout << d[s];
return 0;
}
for(int x : g[u]) {
for(int j = u % x; j < n; j += x) {
if(d[j] > d[u] + abs(j - u) / x) {
d[j] = d[u] + abs(j - u) / x;
c.push({d[j], j});
}
}
}
}
cout << -1 << '\n';
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:18:5: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
18 | d[f] = 0;
| ^
skyscraper.cpp:24:3: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
24 | if(u == s) {
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1128 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1112 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1112 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1112 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
23 ms |
1112 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
1112 KB |
Output is correct |
28 |
Correct |
1 ms |
1112 KB |
Output is correct |
29 |
Correct |
2 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
3 ms |
1372 KB |
Output is correct |
34 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
24 ms |
1280 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
1 ms |
1112 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
2 ms |
1368 KB |
Output is correct |
30 |
Correct |
1 ms |
1112 KB |
Output is correct |
31 |
Correct |
1 ms |
1116 KB |
Output is correct |
32 |
Correct |
1 ms |
1116 KB |
Output is correct |
33 |
Correct |
3 ms |
1368 KB |
Output is correct |
34 |
Correct |
2 ms |
1368 KB |
Output is correct |
35 |
Correct |
5 ms |
1368 KB |
Output is correct |
36 |
Correct |
1 ms |
1112 KB |
Output is correct |
37 |
Correct |
4 ms |
1372 KB |
Output is correct |
38 |
Correct |
7 ms |
1372 KB |
Output is correct |
39 |
Correct |
5 ms |
1372 KB |
Output is correct |
40 |
Correct |
5 ms |
1372 KB |
Output is correct |
41 |
Correct |
5 ms |
1424 KB |
Output is correct |
42 |
Correct |
4 ms |
1372 KB |
Output is correct |
43 |
Correct |
4 ms |
1372 KB |
Output is correct |
44 |
Correct |
346 ms |
1604 KB |
Output is correct |
45 |
Correct |
7 ms |
1628 KB |
Output is correct |
46 |
Correct |
7 ms |
2084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
1 ms |
1112 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1368 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
23 ms |
1276 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
1112 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
2 ms |
1372 KB |
Output is correct |
30 |
Correct |
1 ms |
1116 KB |
Output is correct |
31 |
Correct |
2 ms |
1116 KB |
Output is correct |
32 |
Correct |
2 ms |
1116 KB |
Output is correct |
33 |
Correct |
3 ms |
1372 KB |
Output is correct |
34 |
Correct |
3 ms |
1372 KB |
Output is correct |
35 |
Correct |
5 ms |
1320 KB |
Output is correct |
36 |
Correct |
1 ms |
1112 KB |
Output is correct |
37 |
Correct |
6 ms |
1368 KB |
Output is correct |
38 |
Correct |
5 ms |
1368 KB |
Output is correct |
39 |
Correct |
5 ms |
1372 KB |
Output is correct |
40 |
Correct |
5 ms |
1372 KB |
Output is correct |
41 |
Correct |
5 ms |
1368 KB |
Output is correct |
42 |
Correct |
4 ms |
1368 KB |
Output is correct |
43 |
Correct |
4 ms |
1368 KB |
Output is correct |
44 |
Correct |
339 ms |
1600 KB |
Output is correct |
45 |
Correct |
7 ms |
1628 KB |
Output is correct |
46 |
Correct |
7 ms |
1628 KB |
Output is correct |
47 |
Correct |
9 ms |
2264 KB |
Output is correct |
48 |
Correct |
5 ms |
1884 KB |
Output is correct |
49 |
Correct |
5 ms |
1884 KB |
Output is correct |
50 |
Correct |
3 ms |
1628 KB |
Output is correct |
51 |
Correct |
12 ms |
3192 KB |
Output is correct |
52 |
Correct |
12 ms |
2776 KB |
Output is correct |
53 |
Correct |
7 ms |
2396 KB |
Output is correct |
54 |
Correct |
3 ms |
1628 KB |
Output is correct |
55 |
Correct |
3 ms |
1372 KB |
Output is correct |
56 |
Execution timed out |
1095 ms |
2776 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |