#include <bits/stdc++.h>
const int MAXN=30007;
using namespace std;
vector<int> g[MAXN],w[MAXN];
set<int> v[MAXN];
bool vi[MAXN];
int dist[MAXN],en;
void dijkstra(int s)
{
priority_queue<pair<int,int> > pq;
pq.push(make_pair(0,s));
while(!pq.empty())
{
int u=pq.top().second,d=-pq.top().first;
pq.pop();
if(vi[u]) continue;
dist[u]=d;
vi[u]=true;
if(u==en) return;
for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) pq.push(make_pair(-d-w[u][i],g[u][i]));
}
}
int main()
{
int n,m,st,t1,t2;
cin>>n>>m;
cin>>st>>t1>>en>>t2;
v[st].insert(-t1);
v[en].insert(-t2);
for(int i=0;i<m-2;i++)
{
cin>>t1>>t2;
v[t1].insert(-t2);
}
for(int i=0;i<n;i++)
{
for(set<int>::iterator it=v[i].begin();it!=v[i].end();it++)
{
int t=-(*it),cur=i+t;
while(cur<n)
{
if(!vi[cur] && v[cur].size()>0)
{
g[i].push_back(cur);
w[i].push_back((cur-i)/t);
vi[cur]=true;
}
if(v[cur].find(-t)!=v[cur].end()) break;
cur+=t;
}
cur=i-t;
while(cur>=0)
{
if(!vi[cur] && v[cur].size()>0)
{
g[i].push_back(cur);
w[i].push_back((i-cur)/t);
vi[cur]=true;
}
if(v[cur].find(-t)!=v[cur].end()) break;
cur-=t;
}
}
for(int j=0;j<g[i].size();j++) vi[g[i][j]]=false;
}
dijkstra(st);
if(!vi[en]) dist[en]=-1;
cout<<dist[en]<<"\n";
}
Compilation message
skyscraper.cpp: In function 'void dijkstra(int)':
skyscraper.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) pq.push(make_pair(-d-w[u][i],g[u][i]));
| ~^~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j=0;j<g[i].size();j++) vi[g[i][j]]=false;
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3160 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
3 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3160 KB |
Output is correct |
5 |
Correct |
1 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3044 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
2 ms |
3164 KB |
Output is correct |
16 |
Correct |
1 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3548 KB |
Output is correct |
18 |
Correct |
2 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
3 ms |
3832 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3160 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
3 ms |
3420 KB |
Output is correct |
25 |
Correct |
3 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
4 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3164 KB |
Output is correct |
30 |
Correct |
1 ms |
3164 KB |
Output is correct |
31 |
Correct |
1 ms |
3164 KB |
Output is correct |
32 |
Correct |
1 ms |
3256 KB |
Output is correct |
33 |
Correct |
2 ms |
3164 KB |
Output is correct |
34 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3160 KB |
Output is correct |
15 |
Correct |
3 ms |
3164 KB |
Output is correct |
16 |
Correct |
2 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
1 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3420 KB |
Output is correct |
21 |
Correct |
1 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3164 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3416 KB |
Output is correct |
26 |
Correct |
2 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
3 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3164 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
1 ms |
3256 KB |
Output is correct |
32 |
Correct |
1 ms |
3164 KB |
Output is correct |
33 |
Correct |
2 ms |
3164 KB |
Output is correct |
34 |
Correct |
2 ms |
3164 KB |
Output is correct |
35 |
Correct |
23 ms |
6100 KB |
Output is correct |
36 |
Correct |
6 ms |
3672 KB |
Output is correct |
37 |
Correct |
22 ms |
6860 KB |
Output is correct |
38 |
Correct |
28 ms |
7120 KB |
Output is correct |
39 |
Correct |
24 ms |
6488 KB |
Output is correct |
40 |
Correct |
23 ms |
6700 KB |
Output is correct |
41 |
Correct |
25 ms |
7520 KB |
Output is correct |
42 |
Correct |
11 ms |
3420 KB |
Output is correct |
43 |
Correct |
10 ms |
3280 KB |
Output is correct |
44 |
Correct |
11 ms |
3928 KB |
Output is correct |
45 |
Correct |
18 ms |
4864 KB |
Output is correct |
46 |
Correct |
18 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3416 KB |
Output is correct |
12 |
Correct |
2 ms |
3160 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
2 ms |
3160 KB |
Output is correct |
16 |
Correct |
1 ms |
3160 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
2 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3420 KB |
Output is correct |
21 |
Correct |
1 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3160 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3160 KB |
Output is correct |
28 |
Correct |
3 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3164 KB |
Output is correct |
30 |
Correct |
1 ms |
3256 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
1 ms |
3164 KB |
Output is correct |
33 |
Correct |
2 ms |
3164 KB |
Output is correct |
34 |
Correct |
2 ms |
3164 KB |
Output is correct |
35 |
Correct |
21 ms |
6124 KB |
Output is correct |
36 |
Correct |
4 ms |
3676 KB |
Output is correct |
37 |
Correct |
21 ms |
6828 KB |
Output is correct |
38 |
Correct |
26 ms |
7192 KB |
Output is correct |
39 |
Correct |
23 ms |
6492 KB |
Output is correct |
40 |
Correct |
23 ms |
6748 KB |
Output is correct |
41 |
Correct |
26 ms |
7640 KB |
Output is correct |
42 |
Correct |
10 ms |
3364 KB |
Output is correct |
43 |
Correct |
10 ms |
3420 KB |
Output is correct |
44 |
Correct |
11 ms |
3676 KB |
Output is correct |
45 |
Correct |
18 ms |
5056 KB |
Output is correct |
46 |
Correct |
18 ms |
4956 KB |
Output is correct |
47 |
Correct |
38 ms |
13276 KB |
Output is correct |
48 |
Correct |
19 ms |
6236 KB |
Output is correct |
49 |
Correct |
16 ms |
5464 KB |
Output is correct |
50 |
Correct |
12 ms |
4956 KB |
Output is correct |
51 |
Correct |
29 ms |
8660 KB |
Output is correct |
52 |
Correct |
31 ms |
8908 KB |
Output is correct |
53 |
Correct |
18 ms |
5976 KB |
Output is correct |
54 |
Correct |
1 ms |
3164 KB |
Output is correct |
55 |
Correct |
1 ms |
3164 KB |
Output is correct |
56 |
Correct |
18 ms |
6688 KB |
Output is correct |
57 |
Correct |
9 ms |
3932 KB |
Output is correct |
58 |
Correct |
8 ms |
3172 KB |
Output is correct |
59 |
Correct |
11 ms |
3420 KB |
Output is correct |
60 |
Correct |
11 ms |
3416 KB |
Output is correct |
61 |
Correct |
12 ms |
3676 KB |
Output is correct |
62 |
Correct |
26 ms |
10576 KB |
Output is correct |
63 |
Correct |
25 ms |
4956 KB |
Output is correct |
64 |
Correct |
26 ms |
4984 KB |
Output is correct |
65 |
Correct |
30 ms |
4952 KB |
Output is correct |
66 |
Correct |
45 ms |
5020 KB |
Output is correct |
67 |
Correct |
43 ms |
5024 KB |
Output is correct |