#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "SKYSCRAPER"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
const int N=30010;
int n,m;
int b[N],p[N],f[N];
priority_queue<ii,vector<ii>,greater<ii>> q;
vector<int> val[N];
main()
{
//freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
n=in,m=in;
forinc(i,1,m) b[i]=in,p[i]=in,val[b[i]].pb(p[i]);
reset(f,127); f[b[1]]=0;
q.push({0,b[1]});
while(q.size())
{
ii u=q.top(); q.pop();
if(u.fi!=f[u.se]) continue;
forv(i,val[u.se])
{
int c=u.fi;
for(int j=u.se+i;j<n;j+=i) if(f[j]>++c) q.push({f[j]=c,j});
c=u.fi;
for(int j=u.se-i;j>=0;j-=i) if(f[j]>++c) q.push({f[j]=c,j});
}
}
cout<<(f[b[2]]<1e9 ? f[b[2]] : -1);
}
Compilation message
skyscraper.cpp:30:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
4 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
4 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
4 ms |
1152 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
3 ms |
1152 KB |
Output is correct |
12 |
Correct |
3 ms |
1152 KB |
Output is correct |
13 |
Correct |
4 ms |
1152 KB |
Output is correct |
14 |
Correct |
4 ms |
1152 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
1152 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
4 ms |
1152 KB |
Output is correct |
12 |
Correct |
3 ms |
1152 KB |
Output is correct |
13 |
Correct |
4 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1280 KB |
Output is correct |
15 |
Correct |
5 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
1280 KB |
Output is correct |
18 |
Correct |
3 ms |
1180 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
7 ms |
1280 KB |
Output is correct |
21 |
Correct |
3 ms |
1152 KB |
Output is correct |
22 |
Correct |
4 ms |
1152 KB |
Output is correct |
23 |
Correct |
4 ms |
1152 KB |
Output is correct |
24 |
Correct |
4 ms |
1280 KB |
Output is correct |
25 |
Correct |
5 ms |
1280 KB |
Output is correct |
26 |
Correct |
7 ms |
1152 KB |
Output is correct |
27 |
Correct |
7 ms |
1152 KB |
Output is correct |
28 |
Correct |
4 ms |
1280 KB |
Output is correct |
29 |
Correct |
4 ms |
1408 KB |
Output is correct |
30 |
Correct |
4 ms |
1280 KB |
Output is correct |
31 |
Correct |
5 ms |
1280 KB |
Output is correct |
32 |
Correct |
4 ms |
1280 KB |
Output is correct |
33 |
Correct |
6 ms |
1408 KB |
Output is correct |
34 |
Correct |
5 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1152 KB |
Output is correct |
3 |
Correct |
4 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1196 KB |
Output is correct |
6 |
Correct |
3 ms |
1280 KB |
Output is correct |
7 |
Correct |
3 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
4 ms |
1280 KB |
Output is correct |
12 |
Correct |
3 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
4 ms |
1280 KB |
Output is correct |
15 |
Correct |
3 ms |
1152 KB |
Output is correct |
16 |
Correct |
3 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
1152 KB |
Output is correct |
18 |
Correct |
3 ms |
1196 KB |
Output is correct |
19 |
Correct |
3 ms |
1152 KB |
Output is correct |
20 |
Correct |
8 ms |
1280 KB |
Output is correct |
21 |
Correct |
4 ms |
1220 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
4 ms |
1152 KB |
Output is correct |
24 |
Correct |
4 ms |
1280 KB |
Output is correct |
25 |
Correct |
5 ms |
1280 KB |
Output is correct |
26 |
Correct |
6 ms |
1152 KB |
Output is correct |
27 |
Correct |
8 ms |
1152 KB |
Output is correct |
28 |
Correct |
3 ms |
1280 KB |
Output is correct |
29 |
Correct |
5 ms |
1408 KB |
Output is correct |
30 |
Correct |
4 ms |
1280 KB |
Output is correct |
31 |
Correct |
4 ms |
1280 KB |
Output is correct |
32 |
Correct |
4 ms |
1280 KB |
Output is correct |
33 |
Correct |
6 ms |
1408 KB |
Output is correct |
34 |
Correct |
5 ms |
1408 KB |
Output is correct |
35 |
Correct |
8 ms |
1636 KB |
Output is correct |
36 |
Correct |
6 ms |
1356 KB |
Output is correct |
37 |
Correct |
8 ms |
1536 KB |
Output is correct |
38 |
Correct |
9 ms |
1664 KB |
Output is correct |
39 |
Correct |
12 ms |
1664 KB |
Output is correct |
40 |
Correct |
10 ms |
1664 KB |
Output is correct |
41 |
Correct |
9 ms |
1792 KB |
Output is correct |
42 |
Correct |
49 ms |
1664 KB |
Output is correct |
43 |
Correct |
61 ms |
1664 KB |
Output is correct |
44 |
Correct |
51 ms |
1664 KB |
Output is correct |
45 |
Correct |
8 ms |
1792 KB |
Output is correct |
46 |
Correct |
8 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1072 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
3 ms |
1152 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Correct |
4 ms |
1152 KB |
Output is correct |
8 |
Correct |
2 ms |
1152 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
11 |
Correct |
4 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
4 ms |
1152 KB |
Output is correct |
14 |
Correct |
4 ms |
1152 KB |
Output is correct |
15 |
Correct |
4 ms |
1280 KB |
Output is correct |
16 |
Correct |
4 ms |
1280 KB |
Output is correct |
17 |
Correct |
4 ms |
1280 KB |
Output is correct |
18 |
Correct |
3 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
21 |
Correct |
4 ms |
1196 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
4 ms |
1152 KB |
Output is correct |
24 |
Correct |
4 ms |
1280 KB |
Output is correct |
25 |
Correct |
4 ms |
1308 KB |
Output is correct |
26 |
Correct |
6 ms |
1152 KB |
Output is correct |
27 |
Correct |
6 ms |
1168 KB |
Output is correct |
28 |
Correct |
3 ms |
1280 KB |
Output is correct |
29 |
Correct |
5 ms |
1408 KB |
Output is correct |
30 |
Correct |
4 ms |
1280 KB |
Output is correct |
31 |
Correct |
4 ms |
1280 KB |
Output is correct |
32 |
Correct |
4 ms |
1280 KB |
Output is correct |
33 |
Correct |
5 ms |
1408 KB |
Output is correct |
34 |
Correct |
5 ms |
1408 KB |
Output is correct |
35 |
Correct |
8 ms |
1664 KB |
Output is correct |
36 |
Correct |
4 ms |
1280 KB |
Output is correct |
37 |
Correct |
7 ms |
1536 KB |
Output is correct |
38 |
Correct |
12 ms |
1792 KB |
Output is correct |
39 |
Correct |
9 ms |
1792 KB |
Output is correct |
40 |
Correct |
9 ms |
1792 KB |
Output is correct |
41 |
Correct |
9 ms |
1792 KB |
Output is correct |
42 |
Correct |
59 ms |
1664 KB |
Output is correct |
43 |
Correct |
47 ms |
1664 KB |
Output is correct |
44 |
Correct |
45 ms |
1664 KB |
Output is correct |
45 |
Correct |
8 ms |
1764 KB |
Output is correct |
46 |
Correct |
10 ms |
1792 KB |
Output is correct |
47 |
Correct |
18 ms |
2432 KB |
Output is correct |
48 |
Correct |
11 ms |
1792 KB |
Output is correct |
49 |
Correct |
9 ms |
1792 KB |
Output is correct |
50 |
Correct |
9 ms |
1664 KB |
Output is correct |
51 |
Correct |
33 ms |
3168 KB |
Output is correct |
52 |
Correct |
30 ms |
2688 KB |
Output is correct |
53 |
Correct |
24 ms |
2688 KB |
Output is correct |
54 |
Correct |
5 ms |
1408 KB |
Output is correct |
55 |
Correct |
5 ms |
1408 KB |
Output is correct |
56 |
Correct |
755 ms |
2688 KB |
Output is correct |
57 |
Correct |
63 ms |
3460 KB |
Output is correct |
58 |
Correct |
808 ms |
1884 KB |
Output is correct |
59 |
Correct |
690 ms |
1792 KB |
Output is correct |
60 |
Correct |
812 ms |
1764 KB |
Output is correct |
61 |
Correct |
609 ms |
1836 KB |
Output is correct |
62 |
Correct |
12 ms |
2304 KB |
Output is correct |
63 |
Correct |
32 ms |
2812 KB |
Output is correct |
64 |
Correct |
57 ms |
3952 KB |
Output is correct |
65 |
Correct |
45 ms |
3960 KB |
Output is correct |
66 |
Correct |
58 ms |
3892 KB |
Output is correct |
67 |
Correct |
59 ms |
3956 KB |
Output is correct |