#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAXN=3e4+10;
vector <pair <int,int> > v[MAXN];
priority_queue <pair <int,int> > q;
int ans[MAXN];
void dejkstra(int start) {
ans[start]=0;
q.push({0,start});
while (!q.empty()) {
int x=q.top().second;
if (-q.top().first!=ans[x]) {
q.pop();
continue;
}
q.pop();
for (auto i:v[x]) {
if (ans[i.first]==-1 || ans[i.first]>ans[x]+i.second) {
ans[i.first]=ans[x]+i.second;
q.push({-ans[i.first],i.first});
}
}
}
}
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m, beg, steps, start, ed;
cin >> n >> m;
for (int j=0;j<m;j++) {
cin >> beg >> steps;
if (j==0) start=beg;
if (j==1) ed=beg;
int br=1;
for (int i=beg+steps;i<n;i+=steps) {
v[beg].push_back({i,br});
br++;
}
br=1;
for (int i=beg-steps;i>=0;i-=steps) {
v[beg].push_back({i,br});
br++;
}
}
for (int i=0;i<n;i++) ans[i]=-1;
dejkstra(start);
cout << ans[ed] << endl;
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:19: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | cout << ans[ed] << endl;
| ^
skyscraper.cpp:49:13: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | dejkstra(start);
| ~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1028 KB |
Output is correct |
8 |
Correct |
1 ms |
1028 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1032 KB |
Output is correct |
11 |
Correct |
2 ms |
1040 KB |
Output is correct |
12 |
Correct |
5 ms |
3216 KB |
Output is correct |
13 |
Correct |
5 ms |
3136 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1028 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
3152 KB |
Output is correct |
13 |
Correct |
5 ms |
3220 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
1036 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
2 ms |
1236 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
54 ms |
33056 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
3 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1172 KB |
Output is correct |
26 |
Correct |
61 ms |
34076 KB |
Output is correct |
27 |
Correct |
60 ms |
34048 KB |
Output is correct |
28 |
Correct |
2 ms |
1236 KB |
Output is correct |
29 |
Correct |
3 ms |
1876 KB |
Output is correct |
30 |
Correct |
2 ms |
1364 KB |
Output is correct |
31 |
Correct |
3 ms |
1492 KB |
Output is correct |
32 |
Correct |
2 ms |
1364 KB |
Output is correct |
33 |
Correct |
4 ms |
2388 KB |
Output is correct |
34 |
Correct |
4 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
1036 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1032 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
1044 KB |
Output is correct |
12 |
Correct |
5 ms |
3152 KB |
Output is correct |
13 |
Correct |
6 ms |
3160 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
2 ms |
1236 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
60 ms |
33128 KB |
Output is correct |
21 |
Correct |
1 ms |
1040 KB |
Output is correct |
22 |
Correct |
2 ms |
1124 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1108 KB |
Output is correct |
26 |
Correct |
61 ms |
34084 KB |
Output is correct |
27 |
Correct |
59 ms |
33976 KB |
Output is correct |
28 |
Correct |
2 ms |
1236 KB |
Output is correct |
29 |
Correct |
3 ms |
1876 KB |
Output is correct |
30 |
Correct |
2 ms |
1364 KB |
Output is correct |
31 |
Correct |
2 ms |
1492 KB |
Output is correct |
32 |
Correct |
2 ms |
1364 KB |
Output is correct |
33 |
Correct |
4 ms |
2388 KB |
Output is correct |
34 |
Correct |
4 ms |
2516 KB |
Output is correct |
35 |
Correct |
7 ms |
2792 KB |
Output is correct |
36 |
Correct |
2 ms |
1224 KB |
Output is correct |
37 |
Correct |
10 ms |
4508 KB |
Output is correct |
38 |
Correct |
11 ms |
3796 KB |
Output is correct |
39 |
Correct |
10 ms |
4052 KB |
Output is correct |
40 |
Correct |
10 ms |
3968 KB |
Output is correct |
41 |
Correct |
10 ms |
3796 KB |
Output is correct |
42 |
Runtime error |
304 ms |
262144 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
3152 KB |
Output is correct |
13 |
Correct |
4 ms |
3160 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
3 ms |
1236 KB |
Output is correct |
18 |
Correct |
2 ms |
1108 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
57 ms |
33152 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
1032 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1108 KB |
Output is correct |
26 |
Correct |
62 ms |
34008 KB |
Output is correct |
27 |
Correct |
59 ms |
34024 KB |
Output is correct |
28 |
Correct |
2 ms |
1236 KB |
Output is correct |
29 |
Correct |
3 ms |
1876 KB |
Output is correct |
30 |
Correct |
2 ms |
1364 KB |
Output is correct |
31 |
Correct |
2 ms |
1492 KB |
Output is correct |
32 |
Correct |
2 ms |
1364 KB |
Output is correct |
33 |
Correct |
4 ms |
2388 KB |
Output is correct |
34 |
Correct |
4 ms |
2516 KB |
Output is correct |
35 |
Correct |
9 ms |
2772 KB |
Output is correct |
36 |
Correct |
2 ms |
1236 KB |
Output is correct |
37 |
Correct |
9 ms |
4436 KB |
Output is correct |
38 |
Correct |
10 ms |
3888 KB |
Output is correct |
39 |
Correct |
11 ms |
4028 KB |
Output is correct |
40 |
Correct |
10 ms |
3924 KB |
Output is correct |
41 |
Correct |
10 ms |
3856 KB |
Output is correct |
42 |
Runtime error |
315 ms |
262144 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |