#include<bits/stdc++.h>
#define ll int
#define ff first
#define ss second
using namespace std;
ll n,m,i,j,dist[30005],b,p,x,y,R;
vector<ll> v[30005];
bitset<30005> vis;
map<ll,ll> mp;
set<pair<ll,ll>> q;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(i=0;i<m;i++){
cin >> b >> p;
v[b].push_back(p);
if(i==0) q.insert({0,b});
if(i==1) R=b;
}
while(!q.empty()){
pair<ll,ll> z=*q.begin();
x=z.ss;
y=z.ff;
q.erase(q.begin());
if(vis[x]) continue;
dist[x]=y;
vis[x]=1;
for(ll i:v[x]){
p=0;
for(b=x+i;b<n;b+=i){
p++;
if(!vis[b]){
if(!mp[b] || mp[b]>y+p){
q.insert({y+p,b});
mp[b]>y+p;
}
}
}
p=0;
for(b=x-i;b>=0;b-=i){
p++;
if(!vis[b]){
if(!mp[b] || mp[b]>y+p){
q.insert({y+p,b});
mp[b]>y+p;
}
}
}
}
}
if(vis[R]) cout << dist[R];
else cout << -1;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:12: warning: value computed is not used [-Wunused-value]
35 | mp[b]>y+p;
skyscraper.cpp:45:12: warning: value computed is not used [-Wunused-value]
45 | mp[b]>y+p;
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1112 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1124 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
2 ms |
1112 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
273 ms |
1368 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
3 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1628 KB |
Output is correct |
26 |
Correct |
16 ms |
1116 KB |
Output is correct |
27 |
Correct |
25 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
1116 KB |
Output is correct |
29 |
Correct |
17 ms |
3416 KB |
Output is correct |
30 |
Correct |
6 ms |
1884 KB |
Output is correct |
31 |
Correct |
8 ms |
1864 KB |
Output is correct |
32 |
Correct |
5 ms |
1628 KB |
Output is correct |
33 |
Correct |
33 ms |
5040 KB |
Output is correct |
34 |
Correct |
33 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
287 ms |
1396 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1112 KB |
Output is correct |
24 |
Correct |
3 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1372 KB |
Output is correct |
26 |
Correct |
16 ms |
1308 KB |
Output is correct |
27 |
Correct |
25 ms |
1112 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
16 ms |
3416 KB |
Output is correct |
30 |
Correct |
5 ms |
1880 KB |
Output is correct |
31 |
Correct |
8 ms |
1884 KB |
Output is correct |
32 |
Correct |
5 ms |
1628 KB |
Output is correct |
33 |
Correct |
32 ms |
5056 KB |
Output is correct |
34 |
Correct |
32 ms |
4952 KB |
Output is correct |
35 |
Correct |
23 ms |
3420 KB |
Output is correct |
36 |
Correct |
3 ms |
1372 KB |
Output is correct |
37 |
Correct |
46 ms |
5456 KB |
Output is correct |
38 |
Correct |
39 ms |
4692 KB |
Output is correct |
39 |
Correct |
43 ms |
5204 KB |
Output is correct |
40 |
Correct |
40 ms |
4824 KB |
Output is correct |
41 |
Correct |
37 ms |
4444 KB |
Output is correct |
42 |
Correct |
238 ms |
1408 KB |
Output is correct |
43 |
Correct |
386 ms |
1408 KB |
Output is correct |
44 |
Correct |
408 ms |
1368 KB |
Output is correct |
45 |
Correct |
129 ms |
6480 KB |
Output is correct |
46 |
Correct |
126 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1192 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
4 ms |
1448 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
266 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
1 ms |
1112 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
3 ms |
1368 KB |
Output is correct |
25 |
Correct |
2 ms |
1372 KB |
Output is correct |
26 |
Correct |
16 ms |
1288 KB |
Output is correct |
27 |
Correct |
27 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
1116 KB |
Output is correct |
29 |
Correct |
17 ms |
3420 KB |
Output is correct |
30 |
Correct |
5 ms |
1628 KB |
Output is correct |
31 |
Correct |
7 ms |
1884 KB |
Output is correct |
32 |
Correct |
5 ms |
1628 KB |
Output is correct |
33 |
Correct |
32 ms |
4868 KB |
Output is correct |
34 |
Correct |
33 ms |
5052 KB |
Output is correct |
35 |
Correct |
24 ms |
3312 KB |
Output is correct |
36 |
Correct |
4 ms |
1372 KB |
Output is correct |
37 |
Correct |
46 ms |
5300 KB |
Output is correct |
38 |
Correct |
39 ms |
4700 KB |
Output is correct |
39 |
Correct |
40 ms |
4948 KB |
Output is correct |
40 |
Correct |
39 ms |
4948 KB |
Output is correct |
41 |
Correct |
37 ms |
4436 KB |
Output is correct |
42 |
Correct |
229 ms |
1408 KB |
Output is correct |
43 |
Correct |
380 ms |
1408 KB |
Output is correct |
44 |
Correct |
414 ms |
1372 KB |
Output is correct |
45 |
Correct |
125 ms |
6316 KB |
Output is correct |
46 |
Correct |
132 ms |
6364 KB |
Output is correct |
47 |
Correct |
247 ms |
22604 KB |
Output is correct |
48 |
Correct |
5 ms |
1628 KB |
Output is correct |
49 |
Correct |
4 ms |
1628 KB |
Output is correct |
50 |
Correct |
3 ms |
1368 KB |
Output is correct |
51 |
Correct |
77 ms |
10180 KB |
Output is correct |
52 |
Correct |
93 ms |
11168 KB |
Output is correct |
53 |
Correct |
21 ms |
5496 KB |
Output is correct |
54 |
Correct |
5 ms |
2560 KB |
Output is correct |
55 |
Correct |
6 ms |
2652 KB |
Output is correct |
56 |
Execution timed out |
1092 ms |
4780 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |