#include <bits/stdc++.h>
#define MAXN 30007
using namespace std;
vector<int> g[MAXN],w[MAXN],v[MAXN],c;
bool vi[MAXN];
int dist[MAXN];
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;
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]));
}
}
bool binarna(int l,int r,int k,int val)
{
if(r<l) return false;
int s=(l+r)/2;
if(v[k][s]==val) return true;
if(val<v[k][s]) return binarna(l,s-1,k,val);
return binarna(s+1,r,k,val);
}
int main()
{
int n,m,st,en,t1,t2;
scanf("%d%d",&n,&m);
scanf("%d%d%d%d",&st,&t1,&en,&t2);
v[st].push_back(t1);
v[en].push_back(t2);
for(int i=0;i<m-2;i++)
{
scanf("%d%d",&t1,&t2);
v[t1].push_back(t2);
}
for(int i=0;i<n;i++) sort(v[i].begin(),v[i].end());
for(int i=0;i<n;i++)
{
for(int j=v[i].size()-1;j>=0;j--) if(j==0 || v[i][j]!=v[i][j-1])
{
int t=v[i][j],cur=i+t,cnt=0;
while(cur<n)
{
cnt++;
if(!vi[cur])
{
g[i].push_back(cur);
w[i].push_back(cnt);
vi[cur]=true;
c.push_back(cur);
}
if(binarna(0,v[cur].size()-1,cur,t)) break;
cur+=t;
}
cur=i-t; cnt=0;
while(cur>=0)
{
cnt++;
if(!vi[cur])
{
g[i].push_back(cur);
w[i].push_back(cnt);
vi[cur]=true;
c.push_back(cur);
}
if(binarna(0,v[cur].size()-1,cur,t)) break;
cur-=t;
}
}
for(int j=0;j<c.size();j++) vi[c[j]]=false;
c.clear();
}
dijkstra(st);
if(!vi[en]) dist[en]=-1;
printf("%d",dist[en]);
}
Compilation message
skyscraper.cpp: In function 'void dijkstra(int)':
skyscraper.cpp:18:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<c.size();j++) vi[c[j]]=false;
~^~~~~~~~~
skyscraper.cpp:32: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:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d",&st,&t1,&en,&t2);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&t1,&t2);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
4 ms |
2536 KB |
Output is correct |
3 |
Correct |
3 ms |
2612 KB |
Output is correct |
4 |
Correct |
4 ms |
2612 KB |
Output is correct |
5 |
Correct |
5 ms |
2660 KB |
Output is correct |
6 |
Correct |
4 ms |
2724 KB |
Output is correct |
7 |
Correct |
4 ms |
2724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2724 KB |
Output is correct |
2 |
Correct |
4 ms |
2724 KB |
Output is correct |
3 |
Correct |
4 ms |
2724 KB |
Output is correct |
4 |
Correct |
5 ms |
2724 KB |
Output is correct |
5 |
Correct |
4 ms |
2724 KB |
Output is correct |
6 |
Correct |
4 ms |
2724 KB |
Output is correct |
7 |
Correct |
4 ms |
2724 KB |
Output is correct |
8 |
Correct |
6 ms |
2724 KB |
Output is correct |
9 |
Correct |
5 ms |
2724 KB |
Output is correct |
10 |
Correct |
6 ms |
2796 KB |
Output is correct |
11 |
Correct |
7 ms |
2796 KB |
Output is correct |
12 |
Correct |
6 ms |
2796 KB |
Output is correct |
13 |
Correct |
4 ms |
2796 KB |
Output is correct |
14 |
Correct |
6 ms |
2796 KB |
Output is correct |
15 |
Correct |
4 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2796 KB |
Output is correct |
2 |
Correct |
5 ms |
2796 KB |
Output is correct |
3 |
Correct |
5 ms |
2796 KB |
Output is correct |
4 |
Correct |
4 ms |
2796 KB |
Output is correct |
5 |
Correct |
4 ms |
2796 KB |
Output is correct |
6 |
Correct |
5 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
4 ms |
2796 KB |
Output is correct |
9 |
Correct |
4 ms |
2796 KB |
Output is correct |
10 |
Correct |
5 ms |
2796 KB |
Output is correct |
11 |
Correct |
6 ms |
2812 KB |
Output is correct |
12 |
Correct |
4 ms |
2812 KB |
Output is correct |
13 |
Correct |
6 ms |
2812 KB |
Output is correct |
14 |
Correct |
5 ms |
2812 KB |
Output is correct |
15 |
Correct |
4 ms |
2812 KB |
Output is correct |
16 |
Correct |
4 ms |
2812 KB |
Output is correct |
17 |
Correct |
8 ms |
2940 KB |
Output is correct |
18 |
Correct |
5 ms |
2940 KB |
Output is correct |
19 |
Correct |
6 ms |
2940 KB |
Output is correct |
20 |
Correct |
6 ms |
2940 KB |
Output is correct |
21 |
Correct |
4 ms |
2940 KB |
Output is correct |
22 |
Correct |
5 ms |
2940 KB |
Output is correct |
23 |
Correct |
5 ms |
2940 KB |
Output is correct |
24 |
Correct |
7 ms |
2940 KB |
Output is correct |
25 |
Correct |
6 ms |
2940 KB |
Output is correct |
26 |
Correct |
5 ms |
2940 KB |
Output is correct |
27 |
Correct |
6 ms |
2940 KB |
Output is correct |
28 |
Correct |
7 ms |
3068 KB |
Output is correct |
29 |
Correct |
11 ms |
3456 KB |
Output is correct |
30 |
Correct |
6 ms |
3456 KB |
Output is correct |
31 |
Correct |
9 ms |
3456 KB |
Output is correct |
32 |
Correct |
6 ms |
3456 KB |
Output is correct |
33 |
Correct |
17 ms |
3960 KB |
Output is correct |
34 |
Correct |
15 ms |
3960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3960 KB |
Output is correct |
2 |
Correct |
3 ms |
3960 KB |
Output is correct |
3 |
Correct |
4 ms |
3960 KB |
Output is correct |
4 |
Correct |
4 ms |
3960 KB |
Output is correct |
5 |
Correct |
4 ms |
3960 KB |
Output is correct |
6 |
Correct |
4 ms |
3960 KB |
Output is correct |
7 |
Correct |
4 ms |
3960 KB |
Output is correct |
8 |
Correct |
4 ms |
3960 KB |
Output is correct |
9 |
Correct |
5 ms |
3960 KB |
Output is correct |
10 |
Correct |
5 ms |
3960 KB |
Output is correct |
11 |
Correct |
6 ms |
3960 KB |
Output is correct |
12 |
Correct |
5 ms |
3960 KB |
Output is correct |
13 |
Correct |
5 ms |
3960 KB |
Output is correct |
14 |
Correct |
5 ms |
3960 KB |
Output is correct |
15 |
Correct |
5 ms |
3960 KB |
Output is correct |
16 |
Correct |
6 ms |
3960 KB |
Output is correct |
17 |
Correct |
8 ms |
3960 KB |
Output is correct |
18 |
Correct |
5 ms |
3960 KB |
Output is correct |
19 |
Correct |
4 ms |
3960 KB |
Output is correct |
20 |
Correct |
6 ms |
3960 KB |
Output is correct |
21 |
Correct |
5 ms |
3960 KB |
Output is correct |
22 |
Correct |
5 ms |
3960 KB |
Output is correct |
23 |
Correct |
5 ms |
3960 KB |
Output is correct |
24 |
Correct |
7 ms |
3960 KB |
Output is correct |
25 |
Correct |
6 ms |
3960 KB |
Output is correct |
26 |
Correct |
6 ms |
3960 KB |
Output is correct |
27 |
Correct |
5 ms |
3960 KB |
Output is correct |
28 |
Correct |
6 ms |
3960 KB |
Output is correct |
29 |
Correct |
10 ms |
3960 KB |
Output is correct |
30 |
Correct |
9 ms |
3960 KB |
Output is correct |
31 |
Correct |
7 ms |
3960 KB |
Output is correct |
32 |
Correct |
6 ms |
3960 KB |
Output is correct |
33 |
Correct |
14 ms |
3960 KB |
Output is correct |
34 |
Correct |
15 ms |
3960 KB |
Output is correct |
35 |
Correct |
24 ms |
4472 KB |
Output is correct |
36 |
Correct |
7 ms |
4472 KB |
Output is correct |
37 |
Correct |
37 ms |
5996 KB |
Output is correct |
38 |
Correct |
36 ms |
5996 KB |
Output is correct |
39 |
Correct |
36 ms |
5996 KB |
Output is correct |
40 |
Correct |
37 ms |
5996 KB |
Output is correct |
41 |
Correct |
38 ms |
5996 KB |
Output is correct |
42 |
Correct |
10 ms |
5996 KB |
Output is correct |
43 |
Correct |
11 ms |
5996 KB |
Output is correct |
44 |
Correct |
10 ms |
5996 KB |
Output is correct |
45 |
Correct |
67 ms |
7548 KB |
Output is correct |
46 |
Correct |
74 ms |
7616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7616 KB |
Output is correct |
2 |
Correct |
4 ms |
7616 KB |
Output is correct |
3 |
Correct |
5 ms |
7616 KB |
Output is correct |
4 |
Correct |
4 ms |
7616 KB |
Output is correct |
5 |
Correct |
6 ms |
7616 KB |
Output is correct |
6 |
Correct |
5 ms |
7616 KB |
Output is correct |
7 |
Correct |
6 ms |
7616 KB |
Output is correct |
8 |
Correct |
5 ms |
7616 KB |
Output is correct |
9 |
Correct |
5 ms |
7616 KB |
Output is correct |
10 |
Correct |
5 ms |
7616 KB |
Output is correct |
11 |
Correct |
6 ms |
7616 KB |
Output is correct |
12 |
Correct |
5 ms |
7616 KB |
Output is correct |
13 |
Correct |
4 ms |
7616 KB |
Output is correct |
14 |
Correct |
6 ms |
7616 KB |
Output is correct |
15 |
Correct |
7 ms |
7616 KB |
Output is correct |
16 |
Correct |
4 ms |
7616 KB |
Output is correct |
17 |
Correct |
6 ms |
7616 KB |
Output is correct |
18 |
Correct |
4 ms |
7616 KB |
Output is correct |
19 |
Correct |
5 ms |
7616 KB |
Output is correct |
20 |
Correct |
5 ms |
7616 KB |
Output is correct |
21 |
Correct |
5 ms |
7616 KB |
Output is correct |
22 |
Correct |
6 ms |
7616 KB |
Output is correct |
23 |
Correct |
6 ms |
7616 KB |
Output is correct |
24 |
Correct |
8 ms |
7616 KB |
Output is correct |
25 |
Correct |
7 ms |
7616 KB |
Output is correct |
26 |
Correct |
7 ms |
7616 KB |
Output is correct |
27 |
Correct |
5 ms |
7616 KB |
Output is correct |
28 |
Correct |
6 ms |
7616 KB |
Output is correct |
29 |
Correct |
11 ms |
7616 KB |
Output is correct |
30 |
Correct |
6 ms |
7616 KB |
Output is correct |
31 |
Correct |
7 ms |
7616 KB |
Output is correct |
32 |
Correct |
6 ms |
7616 KB |
Output is correct |
33 |
Correct |
14 ms |
7616 KB |
Output is correct |
34 |
Correct |
14 ms |
7616 KB |
Output is correct |
35 |
Correct |
24 ms |
7616 KB |
Output is correct |
36 |
Correct |
9 ms |
7616 KB |
Output is correct |
37 |
Correct |
37 ms |
7616 KB |
Output is correct |
38 |
Correct |
36 ms |
7616 KB |
Output is correct |
39 |
Correct |
44 ms |
7616 KB |
Output is correct |
40 |
Correct |
48 ms |
7616 KB |
Output is correct |
41 |
Correct |
38 ms |
7616 KB |
Output is correct |
42 |
Correct |
11 ms |
7616 KB |
Output is correct |
43 |
Correct |
11 ms |
7616 KB |
Output is correct |
44 |
Correct |
11 ms |
7616 KB |
Output is correct |
45 |
Correct |
69 ms |
7616 KB |
Output is correct |
46 |
Correct |
81 ms |
7616 KB |
Output is correct |
47 |
Correct |
174 ms |
16232 KB |
Output is correct |
48 |
Correct |
29 ms |
16232 KB |
Output is correct |
49 |
Correct |
26 ms |
16232 KB |
Output is correct |
50 |
Correct |
26 ms |
16232 KB |
Output is correct |
51 |
Correct |
85 ms |
16232 KB |
Output is correct |
52 |
Correct |
101 ms |
16232 KB |
Output is correct |
53 |
Correct |
35 ms |
16232 KB |
Output is correct |
54 |
Correct |
7 ms |
16232 KB |
Output is correct |
55 |
Correct |
10 ms |
16232 KB |
Output is correct |
56 |
Correct |
29 ms |
16232 KB |
Output is correct |
57 |
Correct |
118 ms |
16232 KB |
Output is correct |
58 |
Correct |
15 ms |
16232 KB |
Output is correct |
59 |
Correct |
18 ms |
16232 KB |
Output is correct |
60 |
Correct |
23 ms |
16232 KB |
Output is correct |
61 |
Correct |
19 ms |
16232 KB |
Output is correct |
62 |
Correct |
65 ms |
16232 KB |
Output is correct |
63 |
Correct |
360 ms |
30184 KB |
Output is correct |
64 |
Correct |
391 ms |
31676 KB |
Output is correct |
65 |
Correct |
710 ms |
41628 KB |
Output is correct |
66 |
Execution timed out |
1093 ms |
57992 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |