#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <map>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 30000;
int v[1 + nmax][2];
vector<int> g[1 + nmax];
unordered_map<int, int> dp[1 + nmax];
int seen[1 + nmax];
queue<pair<int,int>> q;
void processlevel(int node, int cost){
if(seen[node] == 1)
return ;
seen[node] = 1;
for(int h = 0; h < g[node].size(); h++){
int jump2 = g[node][h];
if(dp[node][jump2] == 0){
dp[node][jump2] = cost;
q.push({node, jump2});
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0;i < m; i++) {
cin >> v[i][0] >> v[i][1];
g[v[i][0]].push_back(v[i][1]);
}
processlevel(v[0][0], 1);
while(0 < q.size()){
int node = q.front().first;
int jump = q.front().second;
int cost = dp[node][jump];
if(node == v[1][0]){
cout << cost - 1;
return 0;
}
q.pop();
if(0 <= node - jump)
if(dp[node - jump][jump] == 0) {
dp[node - jump][jump] = cost + 1;
processlevel(node - jump, cost + 1);
q.push({node - jump, jump});
}
if(node + jump < n)
if(dp[node + jump][jump] == 0) {
dp[node + jump][jump] = cost + 1;
processlevel(node + jump, cost + 1);
q.push({node + jump, jump});
}
}
cout << dp[v[1][0]][v[1][1]] - 1;
return 0;
}
Compilation message
skyscraper.cpp: In function 'void processlevel(int, int)':
skyscraper.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int h = 0; h < g[node].size(); h++){
~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2944 KB |
Output is correct |
15 |
Correct |
7 ms |
2944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
7 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2944 KB |
Output is correct |
15 |
Correct |
7 ms |
2944 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
7 ms |
2944 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
9 ms |
2944 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
7 ms |
2944 KB |
Output is correct |
24 |
Correct |
8 ms |
3072 KB |
Output is correct |
25 |
Correct |
6 ms |
2816 KB |
Output is correct |
26 |
Correct |
8 ms |
2816 KB |
Output is correct |
27 |
Correct |
7 ms |
2944 KB |
Output is correct |
28 |
Correct |
10 ms |
3712 KB |
Output is correct |
29 |
Correct |
17 ms |
5248 KB |
Output is correct |
30 |
Correct |
9 ms |
3456 KB |
Output is correct |
31 |
Correct |
13 ms |
4352 KB |
Output is correct |
32 |
Correct |
10 ms |
3712 KB |
Output is correct |
33 |
Correct |
29 ms |
7808 KB |
Output is correct |
34 |
Correct |
18 ms |
5632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2816 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
7 ms |
2944 KB |
Output is correct |
15 |
Correct |
7 ms |
2944 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
7 ms |
2944 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2816 KB |
Output is correct |
20 |
Correct |
7 ms |
2944 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
7 ms |
2944 KB |
Output is correct |
24 |
Correct |
8 ms |
3072 KB |
Output is correct |
25 |
Correct |
7 ms |
2816 KB |
Output is correct |
26 |
Correct |
7 ms |
2816 KB |
Output is correct |
27 |
Correct |
7 ms |
2944 KB |
Output is correct |
28 |
Correct |
10 ms |
3712 KB |
Output is correct |
29 |
Correct |
18 ms |
5376 KB |
Output is correct |
30 |
Correct |
9 ms |
3584 KB |
Output is correct |
31 |
Correct |
13 ms |
4352 KB |
Output is correct |
32 |
Correct |
11 ms |
3712 KB |
Output is correct |
33 |
Correct |
30 ms |
7808 KB |
Output is correct |
34 |
Correct |
19 ms |
5632 KB |
Output is correct |
35 |
Correct |
23 ms |
5248 KB |
Output is correct |
36 |
Correct |
7 ms |
2944 KB |
Output is correct |
37 |
Correct |
17 ms |
4992 KB |
Output is correct |
38 |
Correct |
22 ms |
5760 KB |
Output is correct |
39 |
Correct |
15 ms |
3244 KB |
Output is correct |
40 |
Correct |
14 ms |
3712 KB |
Output is correct |
41 |
Correct |
18 ms |
4864 KB |
Output is correct |
42 |
Correct |
11 ms |
3200 KB |
Output is correct |
43 |
Correct |
12 ms |
3328 KB |
Output is correct |
44 |
Correct |
12 ms |
3200 KB |
Output is correct |
45 |
Correct |
195 ms |
23672 KB |
Output is correct |
46 |
Correct |
99 ms |
15096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2816 KB |
Output is correct |
14 |
Correct |
7 ms |
2944 KB |
Output is correct |
15 |
Correct |
7 ms |
2944 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
7 ms |
2944 KB |
Output is correct |
18 |
Correct |
6 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
7 ms |
2944 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
8 ms |
2944 KB |
Output is correct |
24 |
Correct |
8 ms |
3072 KB |
Output is correct |
25 |
Correct |
8 ms |
2816 KB |
Output is correct |
26 |
Correct |
7 ms |
2816 KB |
Output is correct |
27 |
Correct |
7 ms |
2944 KB |
Output is correct |
28 |
Correct |
10 ms |
3712 KB |
Output is correct |
29 |
Correct |
18 ms |
5248 KB |
Output is correct |
30 |
Correct |
9 ms |
3584 KB |
Output is correct |
31 |
Correct |
13 ms |
4352 KB |
Output is correct |
32 |
Correct |
10 ms |
3712 KB |
Output is correct |
33 |
Correct |
29 ms |
7808 KB |
Output is correct |
34 |
Correct |
19 ms |
5632 KB |
Output is correct |
35 |
Correct |
22 ms |
5376 KB |
Output is correct |
36 |
Correct |
7 ms |
2944 KB |
Output is correct |
37 |
Correct |
17 ms |
4992 KB |
Output is correct |
38 |
Correct |
25 ms |
5760 KB |
Output is correct |
39 |
Correct |
12 ms |
3200 KB |
Output is correct |
40 |
Correct |
14 ms |
3712 KB |
Output is correct |
41 |
Correct |
23 ms |
4856 KB |
Output is correct |
42 |
Correct |
11 ms |
3200 KB |
Output is correct |
43 |
Correct |
12 ms |
3332 KB |
Output is correct |
44 |
Correct |
12 ms |
3200 KB |
Output is correct |
45 |
Correct |
200 ms |
23800 KB |
Output is correct |
46 |
Correct |
103 ms |
15096 KB |
Output is correct |
47 |
Correct |
19 ms |
4736 KB |
Output is correct |
48 |
Correct |
12 ms |
3328 KB |
Output is correct |
49 |
Correct |
12 ms |
3328 KB |
Output is correct |
50 |
Correct |
10 ms |
3200 KB |
Output is correct |
51 |
Correct |
31 ms |
6272 KB |
Output is correct |
52 |
Correct |
35 ms |
6904 KB |
Output is correct |
53 |
Correct |
17 ms |
3968 KB |
Output is correct |
54 |
Correct |
10 ms |
3712 KB |
Output is correct |
55 |
Correct |
12 ms |
4224 KB |
Output is correct |
56 |
Correct |
23 ms |
5888 KB |
Output is correct |
57 |
Correct |
7 ms |
2816 KB |
Output is correct |
58 |
Correct |
25 ms |
6528 KB |
Output is correct |
59 |
Correct |
28 ms |
6144 KB |
Output is correct |
60 |
Correct |
29 ms |
6144 KB |
Output is correct |
61 |
Correct |
25 ms |
6016 KB |
Output is correct |
62 |
Correct |
252 ms |
23800 KB |
Output is correct |
63 |
Execution timed out |
1090 ms |
84844 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |