#include <bits/stdc++.h>
#define MAX 31000
typedef std::pair<short,short> pii; ///Skyscraper .first, level .second
std::map<pii,std::vector<pii>> con;
typedef std::pair<pii,int> ppi;
typedef int bits;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::set<bits> visitou;
int N,M;
std::cin>>N>>M;
bool cachorro[N]={};
std::vector<int> poder[N];
int ha[M],hb[M];
for(int i=0;i!=M;++i){
int a,b;
std::cin>>a>>b;
cachorro[a]=true;
poder[a].push_back(b);
ha[i]=a;
hb[i]=b;
}
pii origem = {ha[0],hb[0]};
pii fim = {ha[1],hb[1]};
std::deque<ppi> deque;
deque.push_back({origem,0});
int count=0;
while(deque.size()){
auto ___ = deque.front();
auto __ = ___.first;
deque.pop_front();
if(count==2e7)break;
if(__.first<0||__.first>=N)continue;
if(visitou.find(*((bits*)&__))!=visitou.end())continue;
visitou.insert(*((bits*)&__));
++count;
if(__==fim){
std::cout<<___.second<<"\n";
return 0;
}
deque.push_back({{__.first+__.second,__.second},___.second+1});
deque.push_back({{__.first-__.second,__.second},___.second+1});
if(cachorro[__.first]){
cachorro[__.first]=false;
for(auto&x:poder[__.first])
deque.push_front({{__.first,x},___.second});
}
}
std::cout<<"-1\n";
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:27: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
37 | if(visitou.find(*((bits*)&__))!=visitou.end())continue;
| ~^~~~~~~~~~~
skyscraper.cpp:38:26: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
38 | visitou.insert(*((bits*)&__));
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
216 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
3 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
588 KB |
Output is correct |
28 |
Correct |
5 ms |
1356 KB |
Output is correct |
29 |
Correct |
22 ms |
3224 KB |
Output is correct |
30 |
Correct |
6 ms |
1100 KB |
Output is correct |
31 |
Correct |
13 ms |
1908 KB |
Output is correct |
32 |
Correct |
9 ms |
1388 KB |
Output is correct |
33 |
Correct |
48 ms |
5956 KB |
Output is correct |
34 |
Correct |
24 ms |
3360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
488 KB |
Output is correct |
24 |
Correct |
3 ms |
716 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
588 KB |
Output is correct |
28 |
Correct |
6 ms |
1356 KB |
Output is correct |
29 |
Correct |
22 ms |
3132 KB |
Output is correct |
30 |
Correct |
5 ms |
1100 KB |
Output is correct |
31 |
Correct |
15 ms |
1840 KB |
Output is correct |
32 |
Correct |
8 ms |
1376 KB |
Output is correct |
33 |
Correct |
50 ms |
5992 KB |
Output is correct |
34 |
Correct |
23 ms |
3404 KB |
Output is correct |
35 |
Correct |
16 ms |
2636 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
8 ms |
1504 KB |
Output is correct |
38 |
Correct |
12 ms |
1604 KB |
Output is correct |
39 |
Correct |
5 ms |
716 KB |
Output is correct |
40 |
Correct |
7 ms |
940 KB |
Output is correct |
41 |
Correct |
7 ms |
1080 KB |
Output is correct |
42 |
Correct |
7 ms |
844 KB |
Output is correct |
43 |
Correct |
6 ms |
1100 KB |
Output is correct |
44 |
Correct |
6 ms |
1100 KB |
Output is correct |
45 |
Correct |
265 ms |
23312 KB |
Output is correct |
46 |
Correct |
127 ms |
12480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
3 ms |
588 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
588 KB |
Output is correct |
28 |
Correct |
7 ms |
1356 KB |
Output is correct |
29 |
Correct |
21 ms |
3148 KB |
Output is correct |
30 |
Correct |
5 ms |
1100 KB |
Output is correct |
31 |
Correct |
12 ms |
1784 KB |
Output is correct |
32 |
Correct |
8 ms |
1356 KB |
Output is correct |
33 |
Correct |
60 ms |
5900 KB |
Output is correct |
34 |
Correct |
26 ms |
3396 KB |
Output is correct |
35 |
Correct |
18 ms |
2636 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
8 ms |
1484 KB |
Output is correct |
38 |
Correct |
9 ms |
1612 KB |
Output is correct |
39 |
Correct |
5 ms |
716 KB |
Output is correct |
40 |
Correct |
6 ms |
1028 KB |
Output is correct |
41 |
Correct |
7 ms |
1100 KB |
Output is correct |
42 |
Correct |
5 ms |
844 KB |
Output is correct |
43 |
Correct |
5 ms |
1100 KB |
Output is correct |
44 |
Correct |
5 ms |
1100 KB |
Output is correct |
45 |
Correct |
289 ms |
23284 KB |
Output is correct |
46 |
Correct |
132 ms |
12560 KB |
Output is correct |
47 |
Correct |
7 ms |
1484 KB |
Output is correct |
48 |
Correct |
5 ms |
1484 KB |
Output is correct |
49 |
Correct |
5 ms |
1484 KB |
Output is correct |
50 |
Correct |
4 ms |
1356 KB |
Output is correct |
51 |
Correct |
25 ms |
4200 KB |
Output is correct |
52 |
Correct |
35 ms |
4676 KB |
Output is correct |
53 |
Correct |
10 ms |
2124 KB |
Output is correct |
54 |
Correct |
5 ms |
1612 KB |
Output is correct |
55 |
Correct |
8 ms |
2196 KB |
Output is correct |
56 |
Correct |
17 ms |
3532 KB |
Output is correct |
57 |
Correct |
2 ms |
1148 KB |
Output is correct |
58 |
Correct |
31 ms |
4584 KB |
Output is correct |
59 |
Correct |
19 ms |
4036 KB |
Output is correct |
60 |
Correct |
20 ms |
4100 KB |
Output is correct |
61 |
Correct |
19 ms |
4132 KB |
Output is correct |
62 |
Correct |
137 ms |
23088 KB |
Output is correct |
63 |
Execution timed out |
1097 ms |
60524 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |