#include <bits/stdc++.h>
using namespace std;
const int O = 3e4 + 5;
const int inf = 1e9;
int n, m, b[O], d[O], p[O];
bool inq[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];
}
for (int i = 1; i <= m; ++ i) d[i] = inf;
d[1] = 0;
priority_queue <int, vector <int>, greater <int>> q;
q.push(1); inq[1] = true;
while (q.size()){
int u = q.top();
q.pop();
inq[u] = false;
for (int v = 1; v <= m; ++ v){
if (v != u && d[v] > d[u] + abs(b[u] - b[v]) / p[u] && abs(b[u] - b[v]) % p[u] == 0){
d[v] = d[u] + abs(b[u] - b[v]) / p[u];
if (inq[v] == false){
q.push(v);
inq[v] = true;
}
}
}
}
if (d[2] >= inf) cout << -1;
else cout << d[2];
}
Compilation message
skyscraper.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
59 ms |
352 KB |
Output is correct |
12 |
Correct |
23 ms |
376 KB |
Output is correct |
13 |
Correct |
22 ms |
368 KB |
Output is correct |
14 |
Correct |
49 ms |
332 KB |
Output is correct |
15 |
Correct |
53 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
59 ms |
332 KB |
Output is correct |
12 |
Correct |
22 ms |
332 KB |
Output is correct |
13 |
Correct |
22 ms |
332 KB |
Output is correct |
14 |
Correct |
53 ms |
332 KB |
Output is correct |
15 |
Correct |
51 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
93 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
28 ms |
372 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
33 ms |
336 KB |
Output is correct |
24 |
Correct |
188 ms |
356 KB |
Output is correct |
25 |
Correct |
145 ms |
332 KB |
Output is correct |
26 |
Correct |
25 ms |
332 KB |
Output is correct |
27 |
Correct |
23 ms |
332 KB |
Output is correct |
28 |
Correct |
31 ms |
332 KB |
Output is correct |
29 |
Correct |
8 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
33 |
Correct |
54 ms |
348 KB |
Output is correct |
34 |
Correct |
46 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
60 ms |
332 KB |
Output is correct |
12 |
Correct |
24 ms |
372 KB |
Output is correct |
13 |
Correct |
24 ms |
368 KB |
Output is correct |
14 |
Correct |
49 ms |
332 KB |
Output is correct |
15 |
Correct |
52 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
93 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
29 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
33 ms |
348 KB |
Output is correct |
24 |
Correct |
194 ms |
340 KB |
Output is correct |
25 |
Correct |
142 ms |
332 KB |
Output is correct |
26 |
Correct |
26 ms |
332 KB |
Output is correct |
27 |
Correct |
23 ms |
332 KB |
Output is correct |
28 |
Correct |
31 ms |
344 KB |
Output is correct |
29 |
Correct |
7 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
33 |
Correct |
54 ms |
332 KB |
Output is correct |
34 |
Correct |
47 ms |
452 KB |
Output is correct |
35 |
Execution timed out |
1089 ms |
788 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
68 ms |
332 KB |
Output is correct |
12 |
Correct |
23 ms |
332 KB |
Output is correct |
13 |
Correct |
24 ms |
332 KB |
Output is correct |
14 |
Correct |
54 ms |
332 KB |
Output is correct |
15 |
Correct |
51 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
92 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
29 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
32 ms |
332 KB |
Output is correct |
24 |
Correct |
189 ms |
356 KB |
Output is correct |
25 |
Correct |
142 ms |
332 KB |
Output is correct |
26 |
Correct |
25 ms |
376 KB |
Output is correct |
27 |
Correct |
24 ms |
368 KB |
Output is correct |
28 |
Correct |
33 ms |
336 KB |
Output is correct |
29 |
Correct |
7 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
54 ms |
452 KB |
Output is correct |
34 |
Correct |
45 ms |
332 KB |
Output is correct |
35 |
Execution timed out |
1084 ms |
784 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |