#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct edge
{
int x,d;
edge() {}
edge(int _x,int _d)
{
x=_x;
d=_d;
}
bool operator<(const edge&e)const
{
return e.d<d;
}
};
int n,m;
vector<edge> v[2000000];
int ver[30001][55];
int s=50,num;
void read()
{
cin>>n>>m;
num=n+m;
for(int i=0; i<n; i++)
{
for(int j=1;j<=s;j++)
{
v[num].push_back({m+i,0});
if(i>=j)
{
v[num].push_back({ver[i-j][j],1});
v[ver[i-j][j]].push_back({num,1});
}
ver[i][j]=num++;
}
}
for(int i=0; i<m; i++)
{
int x,y;
cin>>x>>y;
if(y>s)
{
for(int j=x; j<n; j+=y)
{
//cout<<i<<" "<<j+m<<endl;
v[i].push_back({j+m,(j-x)/y});
}
for(int j=x-y; j>=0; j-=y)
{
//cout<<i<<" "<<j+m<<endl;
v[i].push_back({j+m,(x-j)/y});
}
}
else
{
v[i].push_back({ver[x][y],0});
}
//cout<<x+m<<" "<<i<<endl;
v[x+m].push_back({i,0});
}
}
int d[2000000];
priority_queue<edge> q;
void dijkstra()
{
for(int i=0; i<=num; i++)
d[i]=1e9;
d[0]=0;
q.push({0,0});
while(q.size())
{
edge e=q.top();
//cout<<e.x<<endl;
q.pop();
if(d[e.x]>=e.d)
{
for(int i=0; i<v[e.x].size(); i++)
{
edge nb=v[e.x][i];
if(nb.d+e.d<d[nb.x])
{
d[nb.x]=nb.d+e.d;
q.push({nb.x,d[nb.x]});
}
}
}
}
}
int main()
{
read();
dijkstra();
if(d[1]==1e9)d[1]=-1;
cout<<d[1]<<endl;
return 0;
}
Compilation message
skyscraper.cpp: In function 'void dijkstra()':
skyscraper.cpp:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int i=0; i<v[e.x].size(); i++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
51024 KB |
Output is correct |
2 |
Correct |
9 ms |
51024 KB |
Output is correct |
3 |
Correct |
9 ms |
51176 KB |
Output is correct |
4 |
Correct |
9 ms |
51024 KB |
Output is correct |
5 |
Correct |
9 ms |
51268 KB |
Output is correct |
6 |
Correct |
9 ms |
51024 KB |
Output is correct |
7 |
Correct |
9 ms |
51024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51024 KB |
Output is correct |
2 |
Correct |
10 ms |
51024 KB |
Output is correct |
3 |
Correct |
11 ms |
51192 KB |
Output is correct |
4 |
Correct |
9 ms |
51164 KB |
Output is correct |
5 |
Correct |
10 ms |
51040 KB |
Output is correct |
6 |
Correct |
9 ms |
51024 KB |
Output is correct |
7 |
Correct |
9 ms |
51024 KB |
Output is correct |
8 |
Correct |
9 ms |
51280 KB |
Output is correct |
9 |
Correct |
10 ms |
51160 KB |
Output is correct |
10 |
Correct |
10 ms |
51452 KB |
Output is correct |
11 |
Correct |
11 ms |
51584 KB |
Output is correct |
12 |
Correct |
10 ms |
51536 KB |
Output is correct |
13 |
Correct |
10 ms |
51536 KB |
Output is correct |
14 |
Correct |
11 ms |
51536 KB |
Output is correct |
15 |
Correct |
11 ms |
51536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
51024 KB |
Output is correct |
2 |
Correct |
9 ms |
51024 KB |
Output is correct |
3 |
Correct |
9 ms |
51188 KB |
Output is correct |
4 |
Correct |
9 ms |
51024 KB |
Output is correct |
5 |
Correct |
10 ms |
51024 KB |
Output is correct |
6 |
Correct |
12 ms |
51024 KB |
Output is correct |
7 |
Correct |
11 ms |
51024 KB |
Output is correct |
8 |
Correct |
10 ms |
51452 KB |
Output is correct |
9 |
Correct |
10 ms |
51280 KB |
Output is correct |
10 |
Correct |
10 ms |
51488 KB |
Output is correct |
11 |
Correct |
10 ms |
51536 KB |
Output is correct |
12 |
Correct |
10 ms |
51536 KB |
Output is correct |
13 |
Correct |
10 ms |
51536 KB |
Output is correct |
14 |
Correct |
10 ms |
51536 KB |
Output is correct |
15 |
Correct |
11 ms |
51536 KB |
Output is correct |
16 |
Correct |
10 ms |
51536 KB |
Output is correct |
17 |
Correct |
15 ms |
53072 KB |
Output is correct |
18 |
Correct |
18 ms |
57400 KB |
Output is correct |
19 |
Correct |
21 ms |
58192 KB |
Output is correct |
20 |
Correct |
21 ms |
58192 KB |
Output is correct |
21 |
Correct |
12 ms |
52048 KB |
Output is correct |
22 |
Correct |
18 ms |
57680 KB |
Output is correct |
23 |
Correct |
19 ms |
57336 KB |
Output is correct |
24 |
Correct |
21 ms |
57936 KB |
Output is correct |
25 |
Correct |
21 ms |
58192 KB |
Output is correct |
26 |
Correct |
22 ms |
58192 KB |
Output is correct |
27 |
Correct |
22 ms |
58192 KB |
Output is correct |
28 |
Correct |
24 ms |
58192 KB |
Output is correct |
29 |
Correct |
24 ms |
58360 KB |
Output is correct |
30 |
Correct |
23 ms |
57936 KB |
Output is correct |
31 |
Correct |
24 ms |
57936 KB |
Output is correct |
32 |
Correct |
28 ms |
57936 KB |
Output is correct |
33 |
Correct |
28 ms |
58448 KB |
Output is correct |
34 |
Correct |
29 ms |
58448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51024 KB |
Output is correct |
2 |
Correct |
9 ms |
51192 KB |
Output is correct |
3 |
Correct |
10 ms |
51024 KB |
Output is correct |
4 |
Correct |
9 ms |
51024 KB |
Output is correct |
5 |
Correct |
9 ms |
51196 KB |
Output is correct |
6 |
Correct |
9 ms |
51024 KB |
Output is correct |
7 |
Correct |
9 ms |
51024 KB |
Output is correct |
8 |
Correct |
9 ms |
51168 KB |
Output is correct |
9 |
Correct |
10 ms |
51280 KB |
Output is correct |
10 |
Correct |
10 ms |
51456 KB |
Output is correct |
11 |
Correct |
10 ms |
51392 KB |
Output is correct |
12 |
Correct |
10 ms |
51536 KB |
Output is correct |
13 |
Correct |
10 ms |
51396 KB |
Output is correct |
14 |
Correct |
11 ms |
51536 KB |
Output is correct |
15 |
Correct |
12 ms |
51528 KB |
Output is correct |
16 |
Correct |
11 ms |
51536 KB |
Output is correct |
17 |
Correct |
15 ms |
53072 KB |
Output is correct |
18 |
Correct |
20 ms |
57544 KB |
Output is correct |
19 |
Correct |
21 ms |
58184 KB |
Output is correct |
20 |
Correct |
21 ms |
58192 KB |
Output is correct |
21 |
Correct |
12 ms |
52048 KB |
Output is correct |
22 |
Correct |
20 ms |
57692 KB |
Output is correct |
23 |
Correct |
25 ms |
57168 KB |
Output is correct |
24 |
Correct |
23 ms |
57948 KB |
Output is correct |
25 |
Correct |
24 ms |
58192 KB |
Output is correct |
26 |
Correct |
22 ms |
58204 KB |
Output is correct |
27 |
Correct |
21 ms |
58192 KB |
Output is correct |
28 |
Correct |
21 ms |
58204 KB |
Output is correct |
29 |
Correct |
24 ms |
58192 KB |
Output is correct |
30 |
Correct |
21 ms |
58104 KB |
Output is correct |
31 |
Correct |
22 ms |
57936 KB |
Output is correct |
32 |
Correct |
22 ms |
58104 KB |
Output is correct |
33 |
Correct |
26 ms |
58448 KB |
Output is correct |
34 |
Correct |
32 ms |
58460 KB |
Output is correct |
35 |
Correct |
32 ms |
58440 KB |
Output is correct |
36 |
Correct |
18 ms |
56144 KB |
Output is correct |
37 |
Correct |
37 ms |
59984 KB |
Output is correct |
38 |
Correct |
47 ms |
60488 KB |
Output is correct |
39 |
Correct |
44 ms |
60240 KB |
Output is correct |
40 |
Correct |
42 ms |
60488 KB |
Output is correct |
41 |
Correct |
42 ms |
60488 KB |
Output is correct |
42 |
Correct |
31 ms |
59844 KB |
Output is correct |
43 |
Correct |
31 ms |
59852 KB |
Output is correct |
44 |
Correct |
28 ms |
59852 KB |
Output is correct |
45 |
Correct |
51 ms |
63564 KB |
Output is correct |
46 |
Correct |
53 ms |
63568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
51192 KB |
Output is correct |
2 |
Correct |
9 ms |
51024 KB |
Output is correct |
3 |
Correct |
9 ms |
51024 KB |
Output is correct |
4 |
Correct |
10 ms |
51196 KB |
Output is correct |
5 |
Correct |
10 ms |
51024 KB |
Output is correct |
6 |
Correct |
10 ms |
51024 KB |
Output is correct |
7 |
Correct |
9 ms |
51152 KB |
Output is correct |
8 |
Correct |
10 ms |
51280 KB |
Output is correct |
9 |
Correct |
10 ms |
51452 KB |
Output is correct |
10 |
Correct |
11 ms |
51280 KB |
Output is correct |
11 |
Correct |
11 ms |
51536 KB |
Output is correct |
12 |
Correct |
11 ms |
51536 KB |
Output is correct |
13 |
Correct |
11 ms |
51536 KB |
Output is correct |
14 |
Correct |
11 ms |
51708 KB |
Output is correct |
15 |
Correct |
11 ms |
51536 KB |
Output is correct |
16 |
Correct |
11 ms |
51764 KB |
Output is correct |
17 |
Correct |
16 ms |
51280 KB |
Output is correct |
18 |
Correct |
22 ms |
54096 KB |
Output is correct |
19 |
Correct |
21 ms |
58192 KB |
Output is correct |
20 |
Correct |
23 ms |
58192 KB |
Output is correct |
21 |
Correct |
14 ms |
52060 KB |
Output is correct |
22 |
Correct |
20 ms |
57640 KB |
Output is correct |
23 |
Correct |
21 ms |
57168 KB |
Output is correct |
24 |
Correct |
22 ms |
57936 KB |
Output is correct |
25 |
Correct |
22 ms |
58184 KB |
Output is correct |
26 |
Correct |
24 ms |
58180 KB |
Output is correct |
27 |
Correct |
25 ms |
58192 KB |
Output is correct |
28 |
Correct |
26 ms |
58192 KB |
Output is correct |
29 |
Correct |
27 ms |
57936 KB |
Output is correct |
30 |
Correct |
25 ms |
57936 KB |
Output is correct |
31 |
Correct |
25 ms |
57936 KB |
Output is correct |
32 |
Correct |
25 ms |
57948 KB |
Output is correct |
33 |
Correct |
30 ms |
58448 KB |
Output is correct |
34 |
Correct |
33 ms |
58664 KB |
Output is correct |
35 |
Correct |
49 ms |
58440 KB |
Output is correct |
36 |
Correct |
21 ms |
56152 KB |
Output is correct |
37 |
Correct |
45 ms |
59984 KB |
Output is correct |
38 |
Correct |
46 ms |
60504 KB |
Output is correct |
39 |
Correct |
44 ms |
60232 KB |
Output is correct |
40 |
Correct |
47 ms |
60332 KB |
Output is correct |
41 |
Correct |
42 ms |
60488 KB |
Output is correct |
42 |
Correct |
32 ms |
59864 KB |
Output is correct |
43 |
Correct |
30 ms |
59852 KB |
Output is correct |
44 |
Correct |
37 ms |
60016 KB |
Output is correct |
45 |
Correct |
50 ms |
63560 KB |
Output is correct |
46 |
Correct |
50 ms |
63736 KB |
Output is correct |
47 |
Correct |
160 ms |
95216 KB |
Output is correct |
48 |
Correct |
135 ms |
118568 KB |
Output is correct |
49 |
Correct |
160 ms |
123340 KB |
Output is correct |
50 |
Correct |
164 ms |
128840 KB |
Output is correct |
51 |
Correct |
236 ms |
135876 KB |
Output is correct |
52 |
Correct |
241 ms |
136032 KB |
Output is correct |
53 |
Correct |
185 ms |
133960 KB |
Output is correct |
54 |
Correct |
166 ms |
132052 KB |
Output is correct |
55 |
Correct |
178 ms |
131656 KB |
Output is correct |
56 |
Correct |
199 ms |
133968 KB |
Output is correct |
57 |
Correct |
297 ms |
133040 KB |
Output is correct |
58 |
Correct |
176 ms |
133572 KB |
Output is correct |
59 |
Correct |
212 ms |
132168 KB |
Output is correct |
60 |
Correct |
203 ms |
134340 KB |
Output is correct |
61 |
Correct |
212 ms |
133900 KB |
Output is correct |
62 |
Correct |
232 ms |
135220 KB |
Output is correct |
63 |
Correct |
261 ms |
158732 KB |
Output is correct |
64 |
Correct |
284 ms |
166936 KB |
Output is correct |
65 |
Correct |
329 ms |
178372 KB |
Output is correct |
66 |
Correct |
561 ms |
202188 KB |
Output is correct |
67 |
Correct |
571 ms |
204368 KB |
Output is correct |