#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define S 30007
#define M 300
using namespace std;
int B[S];
int P[S];
int n,m;
int odw[S];
int odw2[S][M+7];
vector < int > doge[S];
priority_queue < pair < int, pair < int , int > >, vector < pair < int , pair < int , int > > > , greater < pair < int , pair < int , int > > > > q;
void dijkstra(){
q.push({0,{0,B[0]}});
while(!q.empty()){
int koszt = q.top().first;
int pies = q.top().second.first;
int gdzie = q.top().second.second;
q.pop();
if(!odw[gdzie]){
for(int i = 0; i < doge[gdzie].size();i++){
if(P[doge[gdzie][i]] <= M){
q.push({koszt,{doge[gdzie][i],gdzie}});
}else{
int p = 0;
for(int j = gdzie; j >= 0; j -= P[doge[gdzie][i]]){
q.push({koszt+p,{doge[gdzie][i],j}});
p++;
}
p = 0;
for(int j = gdzie; j < n; j += P[doge[gdzie][i]]){
q.push({koszt+p,{doge[gdzie][i],j}});
p++;
}
}
}
odw[gdzie] = koszt+1;
}
if(P[pies] <= M){
if(!odw2[gdzie][P[pies]]){
odw2[gdzie][P[pies]] = 1;
if(gdzie - P[pies] >= 0)
q.push({koszt+1,{pies, gdzie - P[pies]}});
if(gdzie + P[pies] < n)
q.push({koszt+1,{pies, gdzie + P[pies]}});
}
}
}
}
int main(void){
scanf("%d %d",&n,&m);
for(int i = 0; i < m;i++){
scanf("%d %d",&B[i],&P[i]);
doge[B[i]].push_back(i);
}
dijkstra();
if(odw[B[1]]){
printf("%d",odw[B[1]]-1);
}else{
printf("-1");
}
return 0;
}
/*
5 3
0 2
1 1
4 1
*/
Compilation message
skyscraper.cpp: In function 'void dijkstra()':
skyscraper.cpp:29:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0; i < doge[gdzie].size();i++){
| ~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d %d",&B[i],&P[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
3 ms |
1228 KB |
Output is correct |
15 |
Correct |
3 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
996 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
3 ms |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1128 KB |
Output is correct |
14 |
Correct |
3 ms |
1228 KB |
Output is correct |
15 |
Correct |
3 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
996 KB |
Output is correct |
17 |
Correct |
6 ms |
2028 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
3 ms |
3404 KB |
Output is correct |
21 |
Correct |
1 ms |
992 KB |
Output is correct |
22 |
Correct |
1 ms |
972 KB |
Output is correct |
23 |
Correct |
4 ms |
2892 KB |
Output is correct |
24 |
Correct |
7 ms |
3404 KB |
Output is correct |
25 |
Correct |
4 ms |
3404 KB |
Output is correct |
26 |
Correct |
4 ms |
3404 KB |
Output is correct |
27 |
Correct |
4 ms |
3532 KB |
Output is correct |
28 |
Correct |
5 ms |
3404 KB |
Output is correct |
29 |
Correct |
18 ms |
3404 KB |
Output is correct |
30 |
Correct |
6 ms |
3404 KB |
Output is correct |
31 |
Correct |
11 ms |
3404 KB |
Output is correct |
32 |
Correct |
8 ms |
3424 KB |
Output is correct |
33 |
Correct |
35 ms |
3536 KB |
Output is correct |
34 |
Correct |
35 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
3 ms |
1128 KB |
Output is correct |
15 |
Correct |
3 ms |
1164 KB |
Output is correct |
16 |
Correct |
1 ms |
992 KB |
Output is correct |
17 |
Correct |
6 ms |
1996 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
992 KB |
Output is correct |
20 |
Correct |
3 ms |
3404 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
972 KB |
Output is correct |
23 |
Correct |
4 ms |
2892 KB |
Output is correct |
24 |
Correct |
6 ms |
3276 KB |
Output is correct |
25 |
Correct |
4 ms |
3404 KB |
Output is correct |
26 |
Correct |
4 ms |
3476 KB |
Output is correct |
27 |
Correct |
4 ms |
3532 KB |
Output is correct |
28 |
Correct |
4 ms |
3404 KB |
Output is correct |
29 |
Correct |
18 ms |
3476 KB |
Output is correct |
30 |
Correct |
6 ms |
3416 KB |
Output is correct |
31 |
Correct |
11 ms |
3404 KB |
Output is correct |
32 |
Correct |
8 ms |
3452 KB |
Output is correct |
33 |
Correct |
35 ms |
3532 KB |
Output is correct |
34 |
Correct |
35 ms |
3532 KB |
Output is correct |
35 |
Correct |
41 ms |
3704 KB |
Output is correct |
36 |
Correct |
8 ms |
2440 KB |
Output is correct |
37 |
Correct |
66 ms |
4556 KB |
Output is correct |
38 |
Correct |
66 ms |
4716 KB |
Output is correct |
39 |
Correct |
64 ms |
4676 KB |
Output is correct |
40 |
Correct |
64 ms |
4720 KB |
Output is correct |
41 |
Correct |
65 ms |
4748 KB |
Output is correct |
42 |
Correct |
13 ms |
4496 KB |
Output is correct |
43 |
Correct |
13 ms |
4492 KB |
Output is correct |
44 |
Correct |
12 ms |
4496 KB |
Output is correct |
45 |
Correct |
171 ms |
4840 KB |
Output is correct |
46 |
Correct |
170 ms |
4820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
3 ms |
1128 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
2 ms |
1100 KB |
Output is correct |
14 |
Correct |
3 ms |
1228 KB |
Output is correct |
15 |
Correct |
3 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
996 KB |
Output is correct |
17 |
Correct |
6 ms |
1996 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
3 ms |
3404 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
992 KB |
Output is correct |
23 |
Correct |
4 ms |
2920 KB |
Output is correct |
24 |
Correct |
6 ms |
3276 KB |
Output is correct |
25 |
Correct |
5 ms |
3436 KB |
Output is correct |
26 |
Correct |
4 ms |
3404 KB |
Output is correct |
27 |
Correct |
4 ms |
3532 KB |
Output is correct |
28 |
Correct |
5 ms |
3404 KB |
Output is correct |
29 |
Correct |
19 ms |
3456 KB |
Output is correct |
30 |
Correct |
6 ms |
3404 KB |
Output is correct |
31 |
Correct |
11 ms |
3396 KB |
Output is correct |
32 |
Correct |
9 ms |
3404 KB |
Output is correct |
33 |
Correct |
37 ms |
3484 KB |
Output is correct |
34 |
Correct |
35 ms |
3528 KB |
Output is correct |
35 |
Correct |
42 ms |
3748 KB |
Output is correct |
36 |
Correct |
8 ms |
2508 KB |
Output is correct |
37 |
Correct |
67 ms |
4556 KB |
Output is correct |
38 |
Correct |
65 ms |
4804 KB |
Output is correct |
39 |
Correct |
64 ms |
4676 KB |
Output is correct |
40 |
Correct |
66 ms |
4676 KB |
Output is correct |
41 |
Correct |
64 ms |
4784 KB |
Output is correct |
42 |
Correct |
13 ms |
4496 KB |
Output is correct |
43 |
Correct |
12 ms |
4492 KB |
Output is correct |
44 |
Correct |
12 ms |
4492 KB |
Output is correct |
45 |
Correct |
173 ms |
4784 KB |
Output is correct |
46 |
Correct |
177 ms |
4788 KB |
Output is correct |
47 |
Correct |
296 ms |
19120 KB |
Output is correct |
48 |
Correct |
9 ms |
1776 KB |
Output is correct |
49 |
Correct |
8 ms |
1740 KB |
Output is correct |
50 |
Correct |
6 ms |
1612 KB |
Output is correct |
51 |
Correct |
137 ms |
38840 KB |
Output is correct |
52 |
Correct |
145 ms |
38900 KB |
Output is correct |
53 |
Correct |
47 ms |
38256 KB |
Output is correct |
54 |
Correct |
25 ms |
37068 KB |
Output is correct |
55 |
Correct |
26 ms |
37124 KB |
Output is correct |
56 |
Correct |
37 ms |
38528 KB |
Output is correct |
57 |
Correct |
177 ms |
37188 KB |
Output is correct |
58 |
Correct |
43 ms |
38076 KB |
Output is correct |
59 |
Correct |
51 ms |
38344 KB |
Output is correct |
60 |
Correct |
61 ms |
38180 KB |
Output is correct |
61 |
Correct |
53 ms |
38252 KB |
Output is correct |
62 |
Correct |
87 ms |
38552 KB |
Output is correct |
63 |
Correct |
862 ms |
47268 KB |
Output is correct |
64 |
Execution timed out |
1089 ms |
46496 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |