#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int N = 30003;
struct node{
int at,cost;
node(int a, int b){
at = a,cost = b;
}
};
bool operator<(node A,node B){
return A.cost > B.cost;
}
vector<pii>edges,graph[N];
int dist[N];
map<pii,bool>vis;
int dijkstra(int s,int dst,int n)
{
priority_queue<node>pq;
for(int i = 0; i < n;i++)dist[i] = 999999999;
dist[s] = 0;
pq.push(node(s,0));
while(!pq.empty()){
node u = pq.top();
//printf("%d\n",u.at);
pq.pop();
if(u.cost != dist[u.at])continue;
for(pii e: graph[u.at]){
//printf("%d: %d -- %d,%d\n",u.at,e.first,dist[e.first],u.cost+e.second);
if(dist[e.first] > u.cost+e.second){
dist[e.first] = u.cost+e.second;
pq.push(node(e.first,dist[e.first]));
}
}
//exit(0);
}
return dist[dst];
}
int main(int argc, char const *argv[])
{
int n,m,b,a;
scanf("%d%d",&n,&m);
int src = -1,destination = -1;
for(int i = 0; i < m;i++){
scanf("%d%d",&a,&b);
if(vis[{a,b}])continue;
vis[{a,b}] = vis[{b,a}] = true;
if(i == 0)src = a;
if(i == 1)destination = a;
int x = 1;
while(a+b*x < n){
graph[a].push_back({a+b*x,x});
x++;
}
x = 1;
while(a-b*x >= 0){
graph[a].push_back({a-b*x,x});
x++;
}
}
//printf("%d %d\n",src,destination);exit(0);
int k = dijkstra(src,destination,n);
if(k == 999999999)printf("-1\n");
else printf("%d\n",k);
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main(int, const char**)':
skyscraper.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
2 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1016 KB |
Output is correct |
8 |
Correct |
2 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
4 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1016 KB |
Output is correct |
13 |
Correct |
3 ms |
1120 KB |
Output is correct |
14 |
Correct |
5 ms |
1400 KB |
Output is correct |
15 |
Correct |
4 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
1016 KB |
Output is correct |
5 |
Correct |
3 ms |
1016 KB |
Output is correct |
6 |
Correct |
2 ms |
1016 KB |
Output is correct |
7 |
Correct |
2 ms |
1016 KB |
Output is correct |
8 |
Correct |
3 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
4 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1016 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
5 ms |
1272 KB |
Output is correct |
15 |
Correct |
5 ms |
1400 KB |
Output is correct |
16 |
Correct |
4 ms |
1272 KB |
Output is correct |
17 |
Correct |
6 ms |
1528 KB |
Output is correct |
18 |
Correct |
4 ms |
1272 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
75 ms |
33384 KB |
Output is correct |
21 |
Correct |
4 ms |
1144 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
4 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1404 KB |
Output is correct |
25 |
Correct |
5 ms |
1400 KB |
Output is correct |
26 |
Correct |
3 ms |
1272 KB |
Output is correct |
27 |
Correct |
3 ms |
1144 KB |
Output is correct |
28 |
Correct |
5 ms |
1532 KB |
Output is correct |
29 |
Correct |
6 ms |
2040 KB |
Output is correct |
30 |
Correct |
4 ms |
1400 KB |
Output is correct |
31 |
Correct |
5 ms |
1528 KB |
Output is correct |
32 |
Correct |
4 ms |
1400 KB |
Output is correct |
33 |
Correct |
9 ms |
2680 KB |
Output is correct |
34 |
Correct |
10 ms |
2680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
2 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1016 KB |
Output is correct |
8 |
Correct |
3 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
4 ms |
1244 KB |
Output is correct |
12 |
Correct |
3 ms |
1016 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
5 ms |
1400 KB |
Output is correct |
15 |
Correct |
6 ms |
1400 KB |
Output is correct |
16 |
Correct |
4 ms |
1144 KB |
Output is correct |
17 |
Correct |
5 ms |
1528 KB |
Output is correct |
18 |
Correct |
4 ms |
1272 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
76 ms |
33388 KB |
Output is correct |
21 |
Correct |
13 ms |
1148 KB |
Output is correct |
22 |
Correct |
4 ms |
1144 KB |
Output is correct |
23 |
Correct |
4 ms |
1144 KB |
Output is correct |
24 |
Correct |
6 ms |
1400 KB |
Output is correct |
25 |
Correct |
5 ms |
1400 KB |
Output is correct |
26 |
Correct |
4 ms |
1272 KB |
Output is correct |
27 |
Correct |
3 ms |
1144 KB |
Output is correct |
28 |
Correct |
6 ms |
1528 KB |
Output is correct |
29 |
Correct |
6 ms |
2040 KB |
Output is correct |
30 |
Correct |
4 ms |
1400 KB |
Output is correct |
31 |
Correct |
5 ms |
1528 KB |
Output is correct |
32 |
Correct |
4 ms |
1448 KB |
Output is correct |
33 |
Correct |
9 ms |
2680 KB |
Output is correct |
34 |
Correct |
9 ms |
2752 KB |
Output is correct |
35 |
Correct |
47 ms |
5880 KB |
Output is correct |
36 |
Correct |
9 ms |
1784 KB |
Output is correct |
37 |
Correct |
41 ms |
6648 KB |
Output is correct |
38 |
Correct |
58 ms |
7260 KB |
Output is correct |
39 |
Correct |
60 ms |
7544 KB |
Output is correct |
40 |
Correct |
61 ms |
7416 KB |
Output is correct |
41 |
Correct |
56 ms |
7288 KB |
Output is correct |
42 |
Correct |
9 ms |
1272 KB |
Output is correct |
43 |
Correct |
9 ms |
1144 KB |
Output is correct |
44 |
Correct |
81 ms |
33400 KB |
Output is correct |
45 |
Correct |
64 ms |
9336 KB |
Output is correct |
46 |
Correct |
62 ms |
9268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
2 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1016 KB |
Output is correct |
8 |
Correct |
2 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
4 ms |
1272 KB |
Output is correct |
12 |
Correct |
3 ms |
1020 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
5 ms |
1400 KB |
Output is correct |
15 |
Correct |
4 ms |
1404 KB |
Output is correct |
16 |
Correct |
4 ms |
1144 KB |
Output is correct |
17 |
Correct |
5 ms |
1528 KB |
Output is correct |
18 |
Correct |
4 ms |
1244 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
77 ms |
33444 KB |
Output is correct |
21 |
Correct |
4 ms |
1272 KB |
Output is correct |
22 |
Correct |
4 ms |
1144 KB |
Output is correct |
23 |
Correct |
4 ms |
1272 KB |
Output is correct |
24 |
Correct |
6 ms |
1400 KB |
Output is correct |
25 |
Correct |
5 ms |
1400 KB |
Output is correct |
26 |
Correct |
4 ms |
1144 KB |
Output is correct |
27 |
Correct |
4 ms |
1192 KB |
Output is correct |
28 |
Correct |
5 ms |
1528 KB |
Output is correct |
29 |
Correct |
6 ms |
2040 KB |
Output is correct |
30 |
Correct |
4 ms |
1400 KB |
Output is correct |
31 |
Correct |
5 ms |
1528 KB |
Output is correct |
32 |
Correct |
4 ms |
1400 KB |
Output is correct |
33 |
Correct |
8 ms |
2680 KB |
Output is correct |
34 |
Correct |
9 ms |
2680 KB |
Output is correct |
35 |
Correct |
46 ms |
5824 KB |
Output is correct |
36 |
Correct |
9 ms |
1912 KB |
Output is correct |
37 |
Correct |
42 ms |
6776 KB |
Output is correct |
38 |
Correct |
57 ms |
7416 KB |
Output is correct |
39 |
Correct |
56 ms |
7416 KB |
Output is correct |
40 |
Correct |
61 ms |
7416 KB |
Output is correct |
41 |
Correct |
57 ms |
7288 KB |
Output is correct |
42 |
Correct |
9 ms |
1272 KB |
Output is correct |
43 |
Correct |
9 ms |
1144 KB |
Output is correct |
44 |
Correct |
81 ms |
33400 KB |
Output is correct |
45 |
Correct |
57 ms |
9208 KB |
Output is correct |
46 |
Correct |
57 ms |
9208 KB |
Output is correct |
47 |
Correct |
85 ms |
15480 KB |
Output is correct |
48 |
Correct |
46 ms |
6260 KB |
Output is correct |
49 |
Correct |
38 ms |
5240 KB |
Output is correct |
50 |
Correct |
28 ms |
4472 KB |
Output is correct |
51 |
Correct |
83 ms |
9584 KB |
Output is correct |
52 |
Correct |
84 ms |
9720 KB |
Output is correct |
53 |
Correct |
58 ms |
6516 KB |
Output is correct |
54 |
Correct |
4 ms |
1656 KB |
Output is correct |
55 |
Correct |
6 ms |
2036 KB |
Output is correct |
56 |
Runtime error |
515 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
57 |
Halted |
0 ms |
0 KB |
- |