#include <bits/stdc++.h>
#define maxn 30005
#define pii pair<int,int>
using namespace std;
int n,m;
vector<int>p[maxn];
priority_queue<pii>pq;
int dis[maxn];
bool bio[maxn];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>m;
int s;
int e;
for(int i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
p[x].push_back(y);
if(i==0)s=x;
if(i==1)e=x;
}
for(int i=0;i<n;i++)sort(p[i].begin(),p[i].end(),cmp);
if(e==s)
{
cout<<"0"<<endl;
return 0;
}
for(int i=0;i<n;i++)
{
dis[i]=maxn*maxn+55;
bio[i]=false;
}
pq.push({0,s});
dis[s]=0;
while(!pq.empty())
{
int v=pq.top().second;
pq.pop();
if(bio[v])continue;
bio[v]=true;
for(auto x:p[v])
{
for(int i=v%x;i<n;i+=x)
{
if(dis[i]>dis[v]+(abs(i-v))/x)
{
dis[i]=dis[v]+(abs(i-v))/x;
pq.push({-dis[i],i});
}
}
}
}
if(dis[e]<maxn*maxn+1)cout<<dis[e]<<endl;
else cout<<"-1"<<endl;
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:5: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(e==s)
^~
skyscraper.cpp:71:13: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(dis[e]<maxn*maxn+1)cout<<dis[e]<<endl;
~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1148 KB |
Output is correct |
3 |
Correct |
2 ms |
1148 KB |
Output is correct |
4 |
Correct |
3 ms |
1148 KB |
Output is correct |
5 |
Correct |
3 ms |
1148 KB |
Output is correct |
6 |
Correct |
3 ms |
1148 KB |
Output is correct |
7 |
Correct |
3 ms |
1148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1396 KB |
Output is correct |
2 |
Correct |
2 ms |
1396 KB |
Output is correct |
3 |
Correct |
3 ms |
1396 KB |
Output is correct |
4 |
Correct |
2 ms |
1396 KB |
Output is correct |
5 |
Correct |
2 ms |
1396 KB |
Output is correct |
6 |
Correct |
3 ms |
1396 KB |
Output is correct |
7 |
Correct |
3 ms |
1396 KB |
Output is correct |
8 |
Correct |
2 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
1396 KB |
Output is correct |
10 |
Correct |
3 ms |
1396 KB |
Output is correct |
11 |
Correct |
3 ms |
1396 KB |
Output is correct |
12 |
Correct |
4 ms |
1396 KB |
Output is correct |
13 |
Correct |
4 ms |
1396 KB |
Output is correct |
14 |
Correct |
3 ms |
1396 KB |
Output is correct |
15 |
Correct |
4 ms |
1396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1396 KB |
Output is correct |
2 |
Correct |
2 ms |
1396 KB |
Output is correct |
3 |
Correct |
2 ms |
1396 KB |
Output is correct |
4 |
Correct |
2 ms |
1396 KB |
Output is correct |
5 |
Correct |
3 ms |
1396 KB |
Output is correct |
6 |
Correct |
2 ms |
1396 KB |
Output is correct |
7 |
Correct |
3 ms |
1396 KB |
Output is correct |
8 |
Correct |
3 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
1396 KB |
Output is correct |
10 |
Correct |
3 ms |
1396 KB |
Output is correct |
11 |
Correct |
3 ms |
1396 KB |
Output is correct |
12 |
Correct |
4 ms |
1396 KB |
Output is correct |
13 |
Correct |
5 ms |
1396 KB |
Output is correct |
14 |
Correct |
3 ms |
1396 KB |
Output is correct |
15 |
Correct |
3 ms |
1396 KB |
Output is correct |
16 |
Correct |
3 ms |
1408 KB |
Output is correct |
17 |
Correct |
4 ms |
1544 KB |
Output is correct |
18 |
Correct |
3 ms |
1560 KB |
Output is correct |
19 |
Correct |
3 ms |
1560 KB |
Output is correct |
20 |
Correct |
24 ms |
1580 KB |
Output is correct |
21 |
Correct |
3 ms |
1580 KB |
Output is correct |
22 |
Correct |
3 ms |
1580 KB |
Output is correct |
23 |
Correct |
3 ms |
1616 KB |
Output is correct |
24 |
Correct |
4 ms |
1616 KB |
Output is correct |
25 |
Correct |
4 ms |
1704 KB |
Output is correct |
26 |
Correct |
23 ms |
1704 KB |
Output is correct |
27 |
Correct |
22 ms |
1704 KB |
Output is correct |
28 |
Correct |
3 ms |
1704 KB |
Output is correct |
29 |
Correct |
4 ms |
1720 KB |
Output is correct |
30 |
Correct |
3 ms |
1728 KB |
Output is correct |
31 |
Correct |
3 ms |
1736 KB |
Output is correct |
32 |
Correct |
3 ms |
1736 KB |
Output is correct |
33 |
Correct |
4 ms |
1740 KB |
Output is correct |
34 |
Correct |
4 ms |
1752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1752 KB |
Output is correct |
2 |
Correct |
3 ms |
1752 KB |
Output is correct |
3 |
Correct |
3 ms |
1752 KB |
Output is correct |
4 |
Correct |
3 ms |
1752 KB |
Output is correct |
5 |
Correct |
3 ms |
1752 KB |
Output is correct |
6 |
Correct |
2 ms |
1752 KB |
Output is correct |
7 |
Correct |
2 ms |
1752 KB |
Output is correct |
8 |
Correct |
3 ms |
1752 KB |
Output is correct |
9 |
Correct |
2 ms |
1752 KB |
Output is correct |
10 |
Correct |
3 ms |
1752 KB |
Output is correct |
11 |
Correct |
3 ms |
1752 KB |
Output is correct |
12 |
Correct |
5 ms |
1752 KB |
Output is correct |
13 |
Correct |
4 ms |
1752 KB |
Output is correct |
14 |
Correct |
3 ms |
1752 KB |
Output is correct |
15 |
Correct |
3 ms |
1752 KB |
Output is correct |
16 |
Correct |
3 ms |
1752 KB |
Output is correct |
17 |
Correct |
4 ms |
1836 KB |
Output is correct |
18 |
Correct |
3 ms |
1836 KB |
Output is correct |
19 |
Correct |
3 ms |
1864 KB |
Output is correct |
20 |
Correct |
26 ms |
1872 KB |
Output is correct |
21 |
Correct |
3 ms |
1872 KB |
Output is correct |
22 |
Correct |
3 ms |
1872 KB |
Output is correct |
23 |
Correct |
3 ms |
1908 KB |
Output is correct |
24 |
Correct |
4 ms |
1920 KB |
Output is correct |
25 |
Correct |
4 ms |
1940 KB |
Output is correct |
26 |
Correct |
23 ms |
1960 KB |
Output is correct |
27 |
Correct |
22 ms |
1976 KB |
Output is correct |
28 |
Correct |
3 ms |
1992 KB |
Output is correct |
29 |
Correct |
4 ms |
2088 KB |
Output is correct |
30 |
Correct |
3 ms |
2088 KB |
Output is correct |
31 |
Correct |
4 ms |
2088 KB |
Output is correct |
32 |
Correct |
3 ms |
2088 KB |
Output is correct |
33 |
Correct |
4 ms |
2120 KB |
Output is correct |
34 |
Correct |
4 ms |
2132 KB |
Output is correct |
35 |
Correct |
11 ms |
2564 KB |
Output is correct |
36 |
Correct |
4 ms |
2564 KB |
Output is correct |
37 |
Correct |
10 ms |
2704 KB |
Output is correct |
38 |
Correct |
13 ms |
2992 KB |
Output is correct |
39 |
Correct |
13 ms |
3256 KB |
Output is correct |
40 |
Correct |
14 ms |
3580 KB |
Output is correct |
41 |
Correct |
22 ms |
3784 KB |
Output is correct |
42 |
Correct |
325 ms |
4048 KB |
Output is correct |
43 |
Correct |
326 ms |
4256 KB |
Output is correct |
44 |
Correct |
339 ms |
4464 KB |
Output is correct |
45 |
Correct |
14 ms |
4544 KB |
Output is correct |
46 |
Correct |
15 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4844 KB |
Output is correct |
2 |
Correct |
2 ms |
4844 KB |
Output is correct |
3 |
Correct |
3 ms |
4844 KB |
Output is correct |
4 |
Correct |
2 ms |
4844 KB |
Output is correct |
5 |
Correct |
2 ms |
4844 KB |
Output is correct |
6 |
Correct |
2 ms |
4844 KB |
Output is correct |
7 |
Correct |
2 ms |
4844 KB |
Output is correct |
8 |
Correct |
3 ms |
4844 KB |
Output is correct |
9 |
Correct |
3 ms |
4844 KB |
Output is correct |
10 |
Correct |
3 ms |
4844 KB |
Output is correct |
11 |
Correct |
3 ms |
4844 KB |
Output is correct |
12 |
Correct |
4 ms |
4844 KB |
Output is correct |
13 |
Correct |
4 ms |
4844 KB |
Output is correct |
14 |
Correct |
3 ms |
4844 KB |
Output is correct |
15 |
Correct |
3 ms |
4844 KB |
Output is correct |
16 |
Correct |
3 ms |
4844 KB |
Output is correct |
17 |
Correct |
4 ms |
4844 KB |
Output is correct |
18 |
Correct |
3 ms |
4844 KB |
Output is correct |
19 |
Correct |
3 ms |
4844 KB |
Output is correct |
20 |
Correct |
26 ms |
4844 KB |
Output is correct |
21 |
Correct |
3 ms |
4844 KB |
Output is correct |
22 |
Correct |
4 ms |
4844 KB |
Output is correct |
23 |
Correct |
4 ms |
4844 KB |
Output is correct |
24 |
Correct |
5 ms |
4844 KB |
Output is correct |
25 |
Correct |
4 ms |
4844 KB |
Output is correct |
26 |
Correct |
24 ms |
4844 KB |
Output is correct |
27 |
Correct |
24 ms |
4844 KB |
Output is correct |
28 |
Correct |
3 ms |
4844 KB |
Output is correct |
29 |
Correct |
4 ms |
4900 KB |
Output is correct |
30 |
Correct |
3 ms |
4900 KB |
Output is correct |
31 |
Correct |
5 ms |
4900 KB |
Output is correct |
32 |
Correct |
3 ms |
4900 KB |
Output is correct |
33 |
Correct |
5 ms |
4900 KB |
Output is correct |
34 |
Correct |
5 ms |
4904 KB |
Output is correct |
35 |
Correct |
12 ms |
5328 KB |
Output is correct |
36 |
Correct |
5 ms |
5328 KB |
Output is correct |
37 |
Correct |
11 ms |
5544 KB |
Output is correct |
38 |
Correct |
15 ms |
5796 KB |
Output is correct |
39 |
Correct |
12 ms |
6004 KB |
Output is correct |
40 |
Correct |
14 ms |
6344 KB |
Output is correct |
41 |
Correct |
13 ms |
6612 KB |
Output is correct |
42 |
Correct |
344 ms |
6860 KB |
Output is correct |
43 |
Correct |
386 ms |
7080 KB |
Output is correct |
44 |
Correct |
343 ms |
7160 KB |
Output is correct |
45 |
Correct |
13 ms |
7368 KB |
Output is correct |
46 |
Correct |
13 ms |
7540 KB |
Output is correct |
47 |
Correct |
27 ms |
8560 KB |
Output is correct |
48 |
Correct |
11 ms |
8560 KB |
Output is correct |
49 |
Correct |
11 ms |
8560 KB |
Output is correct |
50 |
Correct |
8 ms |
8636 KB |
Output is correct |
51 |
Correct |
36 ms |
10444 KB |
Output is correct |
52 |
Correct |
37 ms |
10444 KB |
Output is correct |
53 |
Correct |
23 ms |
10604 KB |
Output is correct |
54 |
Correct |
5 ms |
10604 KB |
Output is correct |
55 |
Correct |
5 ms |
10604 KB |
Output is correct |
56 |
Execution timed out |
1071 ms |
10836 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |