#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct edge
{
long long x,d;
edge(){}
edge(long long _x,long long _d)
{
x=_x;
d=_d;
}
bool operator<(const edge&e)const
{
return e.d<d;
}
};
long long n,m;
vector<edge> v[200001];
void read()
{
cin>>n>>m;
for(long long i=0;i<m;i++)
{
long long x,y;
cin>>x>>y;
for(long long j=x;j<n;j+=y)
{
//cout<<i<<" "<<j+m<<endl;
v[i].push_back({j+m,(j-x)/y});
}
for(long long j=x-y;j>=0;j-=y)
{
//cout<<i<<" "<<j+m<<endl;
v[i].push_back({j+m,(x-j)/y});
}
//cout<<x+m<<" "<<i<<endl;
v[x+m].push_back({i,0});
}
}
long long d[200001];
priority_queue<edge> q;
void dijkstra()
{
for(long long i=0;i<200000;i++)
d[i]=1e18;
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(long long 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]==1e18)d[1]=-1;
cout<<d[1]<<endl;
return 0;
}
Compilation message
skyscraper.cpp: In function 'void dijkstra()':
skyscraper.cpp:64:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(long long i=0;i<v[e.x].size();i++)
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6536 KB |
Output is correct |
4 |
Correct |
3 ms |
6480 KB |
Output is correct |
5 |
Correct |
3 ms |
6480 KB |
Output is correct |
6 |
Correct |
3 ms |
6480 KB |
Output is correct |
7 |
Correct |
3 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
4 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6480 KB |
Output is correct |
5 |
Correct |
3 ms |
6556 KB |
Output is correct |
6 |
Correct |
3 ms |
6648 KB |
Output is correct |
7 |
Correct |
4 ms |
6480 KB |
Output is correct |
8 |
Correct |
3 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6736 KB |
Output is correct |
11 |
Correct |
4 ms |
6992 KB |
Output is correct |
12 |
Correct |
9 ms |
10576 KB |
Output is correct |
13 |
Correct |
8 ms |
10832 KB |
Output is correct |
14 |
Correct |
4 ms |
6736 KB |
Output is correct |
15 |
Correct |
4 ms |
6736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6480 KB |
Output is correct |
5 |
Correct |
3 ms |
6480 KB |
Output is correct |
6 |
Correct |
4 ms |
6480 KB |
Output is correct |
7 |
Correct |
4 ms |
6480 KB |
Output is correct |
8 |
Correct |
3 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6736 KB |
Output is correct |
11 |
Correct |
5 ms |
7004 KB |
Output is correct |
12 |
Correct |
9 ms |
10576 KB |
Output is correct |
13 |
Correct |
8 ms |
10832 KB |
Output is correct |
14 |
Correct |
4 ms |
6736 KB |
Output is correct |
15 |
Correct |
4 ms |
6736 KB |
Output is correct |
16 |
Correct |
4 ms |
6668 KB |
Output is correct |
17 |
Correct |
6 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
6736 KB |
Output is correct |
19 |
Correct |
4 ms |
6904 KB |
Output is correct |
20 |
Correct |
87 ms |
71000 KB |
Output is correct |
21 |
Correct |
4 ms |
6736 KB |
Output is correct |
22 |
Correct |
4 ms |
6736 KB |
Output is correct |
23 |
Correct |
4 ms |
6736 KB |
Output is correct |
24 |
Correct |
5 ms |
6992 KB |
Output is correct |
25 |
Correct |
7 ms |
7248 KB |
Output is correct |
26 |
Correct |
86 ms |
64584 KB |
Output is correct |
27 |
Correct |
78 ms |
61256 KB |
Output is correct |
28 |
Correct |
5 ms |
7248 KB |
Output is correct |
29 |
Correct |
7 ms |
8272 KB |
Output is correct |
30 |
Correct |
4 ms |
7248 KB |
Output is correct |
31 |
Correct |
4 ms |
7504 KB |
Output is correct |
32 |
Correct |
5 ms |
7248 KB |
Output is correct |
33 |
Correct |
8 ms |
9808 KB |
Output is correct |
34 |
Correct |
11 ms |
9808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
2 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6480 KB |
Output is correct |
5 |
Correct |
3 ms |
6480 KB |
Output is correct |
6 |
Correct |
3 ms |
6620 KB |
Output is correct |
7 |
Correct |
3 ms |
6480 KB |
Output is correct |
8 |
Correct |
3 ms |
6708 KB |
Output is correct |
9 |
Correct |
4 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6736 KB |
Output is correct |
11 |
Correct |
4 ms |
6788 KB |
Output is correct |
12 |
Correct |
8 ms |
10576 KB |
Output is correct |
13 |
Correct |
8 ms |
10832 KB |
Output is correct |
14 |
Correct |
4 ms |
6736 KB |
Output is correct |
15 |
Correct |
4 ms |
6736 KB |
Output is correct |
16 |
Correct |
4 ms |
6736 KB |
Output is correct |
17 |
Correct |
5 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
6736 KB |
Output is correct |
19 |
Correct |
4 ms |
6736 KB |
Output is correct |
20 |
Correct |
79 ms |
70984 KB |
Output is correct |
21 |
Correct |
3 ms |
6736 KB |
Output is correct |
22 |
Correct |
3 ms |
6736 KB |
Output is correct |
23 |
Correct |
4 ms |
6668 KB |
Output is correct |
24 |
Correct |
4 ms |
6992 KB |
Output is correct |
25 |
Correct |
5 ms |
6992 KB |
Output is correct |
26 |
Correct |
87 ms |
64584 KB |
Output is correct |
27 |
Correct |
72 ms |
61256 KB |
Output is correct |
28 |
Correct |
4 ms |
7416 KB |
Output is correct |
29 |
Correct |
6 ms |
8272 KB |
Output is correct |
30 |
Correct |
4 ms |
7248 KB |
Output is correct |
31 |
Correct |
5 ms |
7504 KB |
Output is correct |
32 |
Correct |
5 ms |
7248 KB |
Output is correct |
33 |
Correct |
9 ms |
9808 KB |
Output is correct |
34 |
Correct |
8 ms |
9844 KB |
Output is correct |
35 |
Correct |
21 ms |
11088 KB |
Output is correct |
36 |
Correct |
6 ms |
7248 KB |
Output is correct |
37 |
Correct |
21 ms |
13648 KB |
Output is correct |
38 |
Correct |
23 ms |
13044 KB |
Output is correct |
39 |
Correct |
30 ms |
13376 KB |
Output is correct |
40 |
Correct |
24 ms |
12848 KB |
Output is correct |
41 |
Correct |
25 ms |
12788 KB |
Output is correct |
42 |
Runtime error |
295 ms |
262144 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6656 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6648 KB |
Output is correct |
5 |
Correct |
3 ms |
6480 KB |
Output is correct |
6 |
Correct |
3 ms |
6480 KB |
Output is correct |
7 |
Correct |
3 ms |
6480 KB |
Output is correct |
8 |
Correct |
3 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6736 KB |
Output is correct |
11 |
Correct |
5 ms |
6992 KB |
Output is correct |
12 |
Correct |
8 ms |
10576 KB |
Output is correct |
13 |
Correct |
9 ms |
10800 KB |
Output is correct |
14 |
Correct |
4 ms |
6736 KB |
Output is correct |
15 |
Correct |
4 ms |
6736 KB |
Output is correct |
16 |
Correct |
3 ms |
6736 KB |
Output is correct |
17 |
Correct |
4 ms |
7248 KB |
Output is correct |
18 |
Correct |
4 ms |
6792 KB |
Output is correct |
19 |
Correct |
3 ms |
6904 KB |
Output is correct |
20 |
Correct |
83 ms |
70916 KB |
Output is correct |
21 |
Correct |
4 ms |
6736 KB |
Output is correct |
22 |
Correct |
3 ms |
6736 KB |
Output is correct |
23 |
Correct |
4 ms |
6736 KB |
Output is correct |
24 |
Correct |
5 ms |
6992 KB |
Output is correct |
25 |
Correct |
5 ms |
6992 KB |
Output is correct |
26 |
Correct |
92 ms |
64584 KB |
Output is correct |
27 |
Correct |
72 ms |
61256 KB |
Output is correct |
28 |
Correct |
4 ms |
7248 KB |
Output is correct |
29 |
Correct |
6 ms |
8272 KB |
Output is correct |
30 |
Correct |
4 ms |
7248 KB |
Output is correct |
31 |
Correct |
5 ms |
7672 KB |
Output is correct |
32 |
Correct |
4 ms |
7248 KB |
Output is correct |
33 |
Correct |
8 ms |
9808 KB |
Output is correct |
34 |
Correct |
8 ms |
9808 KB |
Output is correct |
35 |
Correct |
20 ms |
11088 KB |
Output is correct |
36 |
Correct |
5 ms |
7248 KB |
Output is correct |
37 |
Correct |
22 ms |
13648 KB |
Output is correct |
38 |
Correct |
26 ms |
12916 KB |
Output is correct |
39 |
Correct |
27 ms |
13136 KB |
Output is correct |
40 |
Correct |
24 ms |
12880 KB |
Output is correct |
41 |
Correct |
26 ms |
12872 KB |
Output is correct |
42 |
Runtime error |
307 ms |
262144 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |