#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(){
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:34:12: warning: value computed is not used [-Wunused-value]
34 | mp[b]>y+p;
skyscraper.cpp:44:12: warning: value computed is not used [-Wunused-value]
44 | mp[b]>y+p;
# |
결과 |
실행 시간 |
메모리 |
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 |
1152 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 |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1168 KB |
Output is correct |
12 |
Correct |
3 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1156 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 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 |
1124 KB |
Output is correct |
10 |
Correct |
1 ms |
1152 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
3 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1372 KB |
Output is correct |
15 |
Correct |
2 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 |
267 ms |
1400 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 |
1116 KB |
Output is correct |
24 |
Correct |
3 ms |
1412 KB |
Output is correct |
25 |
Correct |
3 ms |
1372 KB |
Output is correct |
26 |
Correct |
16 ms |
1308 KB |
Output is correct |
27 |
Correct |
24 ms |
1124 KB |
Output is correct |
28 |
Correct |
2 ms |
1124 KB |
Output is correct |
29 |
Correct |
17 ms |
3224 KB |
Output is correct |
30 |
Correct |
5 ms |
1636 KB |
Output is correct |
31 |
Correct |
8 ms |
1892 KB |
Output is correct |
32 |
Correct |
5 ms |
1672 KB |
Output is correct |
33 |
Correct |
34 ms |
4912 KB |
Output is correct |
34 |
Correct |
36 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1392 KB |
Output is correct |
2 |
Correct |
1 ms |
1124 KB |
Output is correct |
3 |
Correct |
1 ms |
1124 KB |
Output is correct |
4 |
Correct |
1 ms |
1124 KB |
Output is correct |
5 |
Correct |
1 ms |
1376 KB |
Output is correct |
6 |
Correct |
1 ms |
1120 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 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 |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1112 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
5 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 |
270 ms |
1392 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 |
3 ms |
1368 KB |
Output is correct |
26 |
Correct |
17 ms |
1116 KB |
Output is correct |
27 |
Correct |
26 ms |
1112 KB |
Output is correct |
28 |
Correct |
2 ms |
1116 KB |
Output is correct |
29 |
Correct |
17 ms |
3412 KB |
Output is correct |
30 |
Correct |
6 ms |
1624 KB |
Output is correct |
31 |
Correct |
8 ms |
1884 KB |
Output is correct |
32 |
Correct |
5 ms |
1624 KB |
Output is correct |
33 |
Correct |
38 ms |
4944 KB |
Output is correct |
34 |
Correct |
34 ms |
4956 KB |
Output is correct |
35 |
Correct |
30 ms |
3596 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
51 ms |
5428 KB |
Output is correct |
38 |
Correct |
50 ms |
4880 KB |
Output is correct |
39 |
Correct |
48 ms |
5216 KB |
Output is correct |
40 |
Correct |
47 ms |
5200 KB |
Output is correct |
41 |
Correct |
44 ms |
4700 KB |
Output is correct |
42 |
Correct |
243 ms |
1372 KB |
Output is correct |
43 |
Correct |
390 ms |
1484 KB |
Output is correct |
44 |
Correct |
420 ms |
1712 KB |
Output is correct |
45 |
Correct |
134 ms |
6736 KB |
Output is correct |
46 |
Correct |
138 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1368 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1112 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 |
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 |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
1420 KB |
Output is correct |
18 |
Correct |
1 ms |
1112 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
268 ms |
1384 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1160 KB |
Output is correct |
24 |
Correct |
3 ms |
1372 KB |
Output is correct |
25 |
Correct |
3 ms |
1260 KB |
Output is correct |
26 |
Correct |
17 ms |
1364 KB |
Output is correct |
27 |
Correct |
24 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
1116 KB |
Output is correct |
29 |
Correct |
17 ms |
3320 KB |
Output is correct |
30 |
Correct |
6 ms |
1828 KB |
Output is correct |
31 |
Correct |
8 ms |
1884 KB |
Output is correct |
32 |
Correct |
5 ms |
1628 KB |
Output is correct |
33 |
Correct |
34 ms |
5036 KB |
Output is correct |
34 |
Correct |
34 ms |
4940 KB |
Output is correct |
35 |
Correct |
30 ms |
3664 KB |
Output is correct |
36 |
Correct |
5 ms |
1624 KB |
Output is correct |
37 |
Correct |
52 ms |
5436 KB |
Output is correct |
38 |
Correct |
48 ms |
4948 KB |
Output is correct |
39 |
Correct |
49 ms |
5204 KB |
Output is correct |
40 |
Correct |
52 ms |
5324 KB |
Output is correct |
41 |
Correct |
45 ms |
4492 KB |
Output is correct |
42 |
Correct |
251 ms |
1624 KB |
Output is correct |
43 |
Correct |
406 ms |
1628 KB |
Output is correct |
44 |
Correct |
418 ms |
1720 KB |
Output is correct |
45 |
Correct |
132 ms |
6740 KB |
Output is correct |
46 |
Correct |
133 ms |
6436 KB |
Output is correct |
47 |
Correct |
279 ms |
22868 KB |
Output is correct |
48 |
Correct |
10 ms |
1624 KB |
Output is correct |
49 |
Correct |
10 ms |
1624 KB |
Output is correct |
50 |
Correct |
7 ms |
1628 KB |
Output is correct |
51 |
Correct |
95 ms |
10436 KB |
Output is correct |
52 |
Correct |
107 ms |
11412 KB |
Output is correct |
53 |
Correct |
30 ms |
5724 KB |
Output is correct |
54 |
Correct |
5 ms |
2648 KB |
Output is correct |
55 |
Correct |
6 ms |
2532 KB |
Output is correct |
56 |
Execution timed out |
1032 ms |
4952 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |