#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define MAXN 30009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dis[MAXN];
vector<PII>adj[MAXN];
int s,t;
set<int>st[MAXN];
int main(){
//~ freopen("file.in", "r", stdin);
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
if(i==1)
s=u;
if(i==2)
t=u;
st[u].insert(v);
}
for(int i=0;i<n;i++)
tr(it,st[i]){
int cur=1;
int u=i,v=*it;
for(int j=u-v;j>=0;j-=v){
adj[u].pb(mp(j,cur));
if(st[j].count(v))
break;
cur++;
}
cur=1;u=i,v=*it;
for(int j=u+v;j<n;j+=v){
adj[u].pb(mp(j,cur));
if(st[j].count(v))
break;
cur++;
}
}
priority_queue<pair<int,int> >q;
q.push(mp(0,s));
for(int i=0;i<n;i++)
dis[i]=INF;
dis[s]=0;
while(!q.empty()){
int val=-q.top().ff;
int nd=q.top().ss;
q.pop();
if(dis[nd]!=val)
continue;
tr(it,adj[nd])
if(umin(dis[it->ff],dis[nd]+it->ss))
q.push(mp(-dis[it->ff],it->ff));
}
if(dis[t]==INF)
dis[t]=-1;
printf("%d\n",dis[t]);
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:30:10: 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:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2424 KB |
Output is correct |
2 |
Correct |
3 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2568 KB |
Output is correct |
4 |
Correct |
3 ms |
2568 KB |
Output is correct |
5 |
Correct |
3 ms |
2584 KB |
Output is correct |
6 |
Correct |
4 ms |
2584 KB |
Output is correct |
7 |
Correct |
4 ms |
2584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2712 KB |
Output is correct |
2 |
Correct |
3 ms |
2712 KB |
Output is correct |
3 |
Correct |
3 ms |
2712 KB |
Output is correct |
4 |
Correct |
4 ms |
2712 KB |
Output is correct |
5 |
Correct |
4 ms |
2712 KB |
Output is correct |
6 |
Correct |
3 ms |
2712 KB |
Output is correct |
7 |
Correct |
3 ms |
2712 KB |
Output is correct |
8 |
Correct |
4 ms |
2712 KB |
Output is correct |
9 |
Correct |
4 ms |
2712 KB |
Output is correct |
10 |
Correct |
4 ms |
2712 KB |
Output is correct |
11 |
Correct |
5 ms |
2788 KB |
Output is correct |
12 |
Correct |
4 ms |
2788 KB |
Output is correct |
13 |
Correct |
4 ms |
2788 KB |
Output is correct |
14 |
Correct |
5 ms |
2788 KB |
Output is correct |
15 |
Correct |
5 ms |
2788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2788 KB |
Output is correct |
2 |
Correct |
4 ms |
2788 KB |
Output is correct |
3 |
Correct |
4 ms |
2788 KB |
Output is correct |
4 |
Correct |
3 ms |
2788 KB |
Output is correct |
5 |
Correct |
3 ms |
2788 KB |
Output is correct |
6 |
Correct |
4 ms |
2788 KB |
Output is correct |
7 |
Correct |
3 ms |
2788 KB |
Output is correct |
8 |
Correct |
3 ms |
2788 KB |
Output is correct |
9 |
Correct |
4 ms |
2788 KB |
Output is correct |
10 |
Correct |
4 ms |
2788 KB |
Output is correct |
11 |
Correct |
4 ms |
2796 KB |
Output is correct |
12 |
Correct |
4 ms |
2796 KB |
Output is correct |
13 |
Correct |
4 ms |
2796 KB |
Output is correct |
14 |
Correct |
4 ms |
2876 KB |
Output is correct |
15 |
Correct |
4 ms |
2876 KB |
Output is correct |
16 |
Correct |
4 ms |
2876 KB |
Output is correct |
17 |
Correct |
5 ms |
2928 KB |
Output is correct |
18 |
Correct |
4 ms |
2928 KB |
Output is correct |
19 |
Correct |
4 ms |
2928 KB |
Output is correct |
20 |
Correct |
6 ms |
2928 KB |
Output is correct |
21 |
Correct |
4 ms |
2928 KB |
Output is correct |
22 |
Correct |
4 ms |
2928 KB |
Output is correct |
23 |
Correct |
4 ms |
2928 KB |
Output is correct |
24 |
Correct |
5 ms |
2944 KB |
Output is correct |
25 |
Correct |
6 ms |
2944 KB |
Output is correct |
26 |
Correct |
4 ms |
2944 KB |
Output is correct |
27 |
Correct |
4 ms |
2944 KB |
Output is correct |
28 |
Correct |
6 ms |
3072 KB |
Output is correct |
29 |
Correct |
6 ms |
3456 KB |
Output is correct |
30 |
Correct |
4 ms |
3456 KB |
Output is correct |
31 |
Correct |
5 ms |
3456 KB |
Output is correct |
32 |
Correct |
5 ms |
3456 KB |
Output is correct |
33 |
Correct |
11 ms |
4096 KB |
Output is correct |
34 |
Correct |
8 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4176 KB |
Output is correct |
2 |
Correct |
3 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
4 ms |
4176 KB |
Output is correct |
6 |
Correct |
3 ms |
4176 KB |
Output is correct |
7 |
Correct |
4 ms |
4176 KB |
Output is correct |
8 |
Correct |
4 ms |
4176 KB |
Output is correct |
9 |
Correct |
4 ms |
4176 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
5 ms |
4176 KB |
Output is correct |
12 |
Correct |
4 ms |
4176 KB |
Output is correct |
13 |
Correct |
4 ms |
4176 KB |
Output is correct |
14 |
Correct |
4 ms |
4176 KB |
Output is correct |
15 |
Correct |
4 ms |
4176 KB |
Output is correct |
16 |
Correct |
4 ms |
4176 KB |
Output is correct |
17 |
Correct |
6 ms |
4176 KB |
Output is correct |
18 |
Correct |
4 ms |
4176 KB |
Output is correct |
19 |
Correct |
4 ms |
4176 KB |
Output is correct |
20 |
Correct |
4 ms |
4176 KB |
Output is correct |
21 |
Correct |
4 ms |
4176 KB |
Output is correct |
22 |
Correct |
5 ms |
4176 KB |
Output is correct |
23 |
Correct |
4 ms |
4176 KB |
Output is correct |
24 |
Correct |
5 ms |
4176 KB |
Output is correct |
25 |
Correct |
6 ms |
4176 KB |
Output is correct |
26 |
Correct |
4 ms |
4176 KB |
Output is correct |
27 |
Correct |
4 ms |
4176 KB |
Output is correct |
28 |
Correct |
5 ms |
4176 KB |
Output is correct |
29 |
Correct |
8 ms |
4176 KB |
Output is correct |
30 |
Correct |
4 ms |
4176 KB |
Output is correct |
31 |
Correct |
5 ms |
4176 KB |
Output is correct |
32 |
Correct |
5 ms |
4176 KB |
Output is correct |
33 |
Correct |
8 ms |
4176 KB |
Output is correct |
34 |
Correct |
9 ms |
4176 KB |
Output is correct |
35 |
Correct |
24 ms |
4988 KB |
Output is correct |
36 |
Correct |
6 ms |
4988 KB |
Output is correct |
37 |
Correct |
26 ms |
5628 KB |
Output is correct |
38 |
Correct |
31 ms |
5884 KB |
Output is correct |
39 |
Correct |
33 ms |
5884 KB |
Output is correct |
40 |
Correct |
32 ms |
5884 KB |
Output is correct |
41 |
Correct |
31 ms |
5884 KB |
Output is correct |
42 |
Correct |
10 ms |
5884 KB |
Output is correct |
43 |
Correct |
10 ms |
5884 KB |
Output is correct |
44 |
Correct |
9 ms |
5884 KB |
Output is correct |
45 |
Correct |
36 ms |
8444 KB |
Output is correct |
46 |
Correct |
35 ms |
8444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8444 KB |
Output is correct |
2 |
Correct |
3 ms |
8444 KB |
Output is correct |
3 |
Correct |
3 ms |
8444 KB |
Output is correct |
4 |
Correct |
3 ms |
8444 KB |
Output is correct |
5 |
Correct |
3 ms |
8444 KB |
Output is correct |
6 |
Correct |
3 ms |
8444 KB |
Output is correct |
7 |
Correct |
3 ms |
8444 KB |
Output is correct |
8 |
Correct |
3 ms |
8444 KB |
Output is correct |
9 |
Correct |
3 ms |
8444 KB |
Output is correct |
10 |
Correct |
4 ms |
8444 KB |
Output is correct |
11 |
Correct |
4 ms |
8444 KB |
Output is correct |
12 |
Correct |
4 ms |
8444 KB |
Output is correct |
13 |
Correct |
4 ms |
8444 KB |
Output is correct |
14 |
Correct |
4 ms |
8444 KB |
Output is correct |
15 |
Correct |
4 ms |
8444 KB |
Output is correct |
16 |
Correct |
4 ms |
8444 KB |
Output is correct |
17 |
Correct |
5 ms |
8444 KB |
Output is correct |
18 |
Correct |
4 ms |
8444 KB |
Output is correct |
19 |
Correct |
4 ms |
8444 KB |
Output is correct |
20 |
Correct |
4 ms |
8444 KB |
Output is correct |
21 |
Correct |
4 ms |
8444 KB |
Output is correct |
22 |
Correct |
4 ms |
8444 KB |
Output is correct |
23 |
Correct |
5 ms |
8444 KB |
Output is correct |
24 |
Correct |
5 ms |
8444 KB |
Output is correct |
25 |
Correct |
5 ms |
8444 KB |
Output is correct |
26 |
Correct |
5 ms |
8444 KB |
Output is correct |
27 |
Correct |
4 ms |
8444 KB |
Output is correct |
28 |
Correct |
5 ms |
8444 KB |
Output is correct |
29 |
Correct |
6 ms |
8444 KB |
Output is correct |
30 |
Correct |
6 ms |
8444 KB |
Output is correct |
31 |
Correct |
5 ms |
8444 KB |
Output is correct |
32 |
Correct |
5 ms |
8444 KB |
Output is correct |
33 |
Correct |
9 ms |
8444 KB |
Output is correct |
34 |
Correct |
8 ms |
8444 KB |
Output is correct |
35 |
Correct |
31 ms |
8444 KB |
Output is correct |
36 |
Correct |
9 ms |
8444 KB |
Output is correct |
37 |
Correct |
27 ms |
8444 KB |
Output is correct |
38 |
Correct |
35 ms |
8444 KB |
Output is correct |
39 |
Correct |
33 ms |
8444 KB |
Output is correct |
40 |
Correct |
33 ms |
8444 KB |
Output is correct |
41 |
Correct |
38 ms |
8444 KB |
Output is correct |
42 |
Correct |
11 ms |
8444 KB |
Output is correct |
43 |
Correct |
9 ms |
8444 KB |
Output is correct |
44 |
Correct |
9 ms |
8444 KB |
Output is correct |
45 |
Correct |
39 ms |
8572 KB |
Output is correct |
46 |
Correct |
33 ms |
8572 KB |
Output is correct |
47 |
Correct |
63 ms |
13020 KB |
Output is correct |
48 |
Correct |
23 ms |
13020 KB |
Output is correct |
49 |
Correct |
20 ms |
13020 KB |
Output is correct |
50 |
Correct |
15 ms |
13020 KB |
Output is correct |
51 |
Correct |
60 ms |
13020 KB |
Output is correct |
52 |
Correct |
54 ms |
13020 KB |
Output is correct |
53 |
Correct |
27 ms |
13020 KB |
Output is correct |
54 |
Correct |
6 ms |
13020 KB |
Output is correct |
55 |
Correct |
7 ms |
13020 KB |
Output is correct |
56 |
Correct |
18 ms |
13020 KB |
Output is correct |
57 |
Correct |
51 ms |
13020 KB |
Output is correct |
58 |
Correct |
14 ms |
13020 KB |
Output is correct |
59 |
Correct |
18 ms |
13020 KB |
Output is correct |
60 |
Correct |
16 ms |
13020 KB |
Output is correct |
61 |
Correct |
15 ms |
13020 KB |
Output is correct |
62 |
Correct |
31 ms |
13020 KB |
Output is correct |
63 |
Correct |
91 ms |
27124 KB |
Output is correct |
64 |
Correct |
100 ms |
30292 KB |
Output is correct |
65 |
Correct |
136 ms |
40508 KB |
Output is correct |
66 |
Correct |
236 ms |
67820 KB |
Output is correct |
67 |
Correct |
229 ms |
68068 KB |
Output is correct |