#include <bits/stdc++.h>
#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
#define int long long
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;
priority_queue<pair<int,int >> q;
int b[N], p[N], vis[N];
vector<int > v[N];
main () {
int n, m;
cin >> n >> m;
for(int i = 1;i <= m; i++){
cin >> b[i] >> p[i];
v[b[i]].pb(p[i]);
}
memset(vis, 0x3f3f3f3f, sizeof(vis));
vis[b[1]] = 0;
q.push(mk(0,b[1]));
while(!q.empty()){
pair<int,int > u = q.top();
q.pop();
for(auto i : v[u.sc]){
int cnt = u.fr;
for(int j = u.sc + i; j < n; j += i){
if(vis[j] > ++cnt){
q.push(mk(vis[j] = cnt,j));
}
}
cnt = u.fr;
for(int j = u.sc - i; j >= 0; j -= i){
if(vis[j] > ++cnt){
q.push(mk(vis[j] = cnt,j));
}
}
}
}
int ans = vis[b[2]];
cout << ((ans > 1e9) ? -1 : ans);
}
Compilation message
skyscraper.cpp:21:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6656 KB |
Output is correct |
2 |
Correct |
7 ms |
6528 KB |
Output is correct |
3 |
Correct |
8 ms |
6656 KB |
Output is correct |
4 |
Correct |
8 ms |
6528 KB |
Output is correct |
5 |
Correct |
10 ms |
6528 KB |
Output is correct |
6 |
Correct |
8 ms |
6528 KB |
Output is correct |
7 |
Correct |
8 ms |
6656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6656 KB |
Output is correct |
2 |
Correct |
7 ms |
6528 KB |
Output is correct |
3 |
Correct |
7 ms |
6656 KB |
Output is correct |
4 |
Correct |
7 ms |
6656 KB |
Output is correct |
5 |
Correct |
7 ms |
6656 KB |
Output is correct |
6 |
Correct |
7 ms |
6528 KB |
Output is correct |
7 |
Correct |
7 ms |
6656 KB |
Output is correct |
8 |
Correct |
8 ms |
6528 KB |
Output is correct |
9 |
Correct |
7 ms |
6528 KB |
Output is correct |
10 |
Correct |
9 ms |
6656 KB |
Output is correct |
11 |
Correct |
11 ms |
6656 KB |
Output is correct |
12 |
Correct |
8 ms |
6656 KB |
Output is correct |
13 |
Correct |
9 ms |
6656 KB |
Output is correct |
14 |
Correct |
11 ms |
6656 KB |
Output is correct |
15 |
Correct |
11 ms |
6656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6528 KB |
Output is correct |
2 |
Correct |
8 ms |
6528 KB |
Output is correct |
3 |
Correct |
8 ms |
6644 KB |
Output is correct |
4 |
Correct |
7 ms |
6656 KB |
Output is correct |
5 |
Correct |
7 ms |
6528 KB |
Output is correct |
6 |
Correct |
8 ms |
6656 KB |
Output is correct |
7 |
Correct |
7 ms |
6528 KB |
Output is correct |
8 |
Correct |
8 ms |
6528 KB |
Output is correct |
9 |
Correct |
8 ms |
6528 KB |
Output is correct |
10 |
Correct |
8 ms |
6656 KB |
Output is correct |
11 |
Correct |
11 ms |
6656 KB |
Output is correct |
12 |
Correct |
10 ms |
6656 KB |
Output is correct |
13 |
Correct |
8 ms |
6656 KB |
Output is correct |
14 |
Correct |
10 ms |
6656 KB |
Output is correct |
15 |
Correct |
9 ms |
6656 KB |
Output is correct |
16 |
Correct |
9 ms |
6656 KB |
Output is correct |
17 |
Correct |
32 ms |
6656 KB |
Output is correct |
18 |
Correct |
11 ms |
6656 KB |
Output is correct |
19 |
Correct |
10 ms |
6656 KB |
Output is correct |
20 |
Correct |
12 ms |
6784 KB |
Output is correct |
21 |
Correct |
10 ms |
6656 KB |
Output is correct |
22 |
Correct |
9 ms |
6656 KB |
Output is correct |
23 |
Correct |
12 ms |
6656 KB |
Output is correct |
24 |
Correct |
40 ms |
6784 KB |
Output is correct |
25 |
Correct |
15 ms |
6784 KB |
Output is correct |
26 |
Correct |
12 ms |
6784 KB |
Output is correct |
27 |
Correct |
13 ms |
6784 KB |
Output is correct |
28 |
Correct |
23 ms |
6656 KB |
Output is correct |
29 |
Correct |
10 ms |
6784 KB |
Output is correct |
30 |
Correct |
12 ms |
6656 KB |
Output is correct |
31 |
Correct |
11 ms |
6784 KB |
Output is correct |
32 |
Correct |
10 ms |
6656 KB |
Output is correct |
33 |
Correct |
13 ms |
6912 KB |
Output is correct |
34 |
Correct |
12 ms |
6912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6656 KB |
Output is correct |
2 |
Correct |
8 ms |
6656 KB |
Output is correct |
3 |
Correct |
7 ms |
6528 KB |
Output is correct |
4 |
Correct |
11 ms |
6528 KB |
Output is correct |
5 |
Correct |
8 ms |
6656 KB |
Output is correct |
6 |
Correct |
10 ms |
6656 KB |
Output is correct |
7 |
Correct |
7 ms |
6608 KB |
Output is correct |
8 |
Correct |
10 ms |
6656 KB |
Output is correct |
9 |
Correct |
8 ms |
6656 KB |
Output is correct |
10 |
Correct |
10 ms |
6656 KB |
Output is correct |
11 |
Correct |
10 ms |
6656 KB |
Output is correct |
12 |
Correct |
9 ms |
6656 KB |
Output is correct |
13 |
Correct |
8 ms |
6656 KB |
Output is correct |
14 |
Correct |
10 ms |
6656 KB |
Output is correct |
15 |
Correct |
10 ms |
6628 KB |
Output is correct |
16 |
Correct |
8 ms |
6656 KB |
Output is correct |
17 |
Correct |
32 ms |
6656 KB |
Output is correct |
18 |
Correct |
9 ms |
6656 KB |
Output is correct |
19 |
Correct |
9 ms |
6656 KB |
Output is correct |
20 |
Correct |
16 ms |
6784 KB |
Output is correct |
21 |
Correct |
10 ms |
6684 KB |
Output is correct |
22 |
Correct |
10 ms |
6656 KB |
Output is correct |
23 |
Correct |
14 ms |
6656 KB |
Output is correct |
24 |
Correct |
49 ms |
6776 KB |
Output is correct |
25 |
Correct |
13 ms |
6828 KB |
Output is correct |
26 |
Correct |
11 ms |
6656 KB |
Output is correct |
27 |
Correct |
10 ms |
6784 KB |
Output is correct |
28 |
Correct |
10 ms |
6784 KB |
Output is correct |
29 |
Correct |
11 ms |
6784 KB |
Output is correct |
30 |
Correct |
10 ms |
6656 KB |
Output is correct |
31 |
Correct |
10 ms |
6772 KB |
Output is correct |
32 |
Correct |
10 ms |
6656 KB |
Output is correct |
33 |
Correct |
13 ms |
6832 KB |
Output is correct |
34 |
Correct |
13 ms |
6912 KB |
Output is correct |
35 |
Correct |
274 ms |
7680 KB |
Output is correct |
36 |
Correct |
48 ms |
6912 KB |
Output is correct |
37 |
Correct |
784 ms |
7544 KB |
Output is correct |
38 |
Correct |
626 ms |
7800 KB |
Output is correct |
39 |
Correct |
775 ms |
7928 KB |
Output is correct |
40 |
Correct |
923 ms |
7800 KB |
Output is correct |
41 |
Correct |
938 ms |
7916 KB |
Output is correct |
42 |
Correct |
58 ms |
7676 KB |
Output is correct |
43 |
Correct |
59 ms |
7676 KB |
Output is correct |
44 |
Correct |
59 ms |
7676 KB |
Output is correct |
45 |
Correct |
37 ms |
7800 KB |
Output is correct |
46 |
Correct |
32 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6528 KB |
Output is correct |
2 |
Correct |
8 ms |
6528 KB |
Output is correct |
3 |
Correct |
8 ms |
6656 KB |
Output is correct |
4 |
Correct |
8 ms |
6576 KB |
Output is correct |
5 |
Correct |
9 ms |
6656 KB |
Output is correct |
6 |
Correct |
9 ms |
6656 KB |
Output is correct |
7 |
Correct |
7 ms |
6528 KB |
Output is correct |
8 |
Correct |
8 ms |
6656 KB |
Output is correct |
9 |
Correct |
8 ms |
6656 KB |
Output is correct |
10 |
Correct |
9 ms |
6656 KB |
Output is correct |
11 |
Correct |
10 ms |
6656 KB |
Output is correct |
12 |
Correct |
9 ms |
6656 KB |
Output is correct |
13 |
Correct |
9 ms |
6656 KB |
Output is correct |
14 |
Correct |
12 ms |
6656 KB |
Output is correct |
15 |
Correct |
9 ms |
6656 KB |
Output is correct |
16 |
Correct |
9 ms |
6656 KB |
Output is correct |
17 |
Correct |
36 ms |
6656 KB |
Output is correct |
18 |
Correct |
10 ms |
6656 KB |
Output is correct |
19 |
Correct |
10 ms |
6656 KB |
Output is correct |
20 |
Correct |
14 ms |
6784 KB |
Output is correct |
21 |
Correct |
9 ms |
6656 KB |
Output is correct |
22 |
Correct |
10 ms |
6784 KB |
Output is correct |
23 |
Correct |
14 ms |
6732 KB |
Output is correct |
24 |
Correct |
52 ms |
6784 KB |
Output is correct |
25 |
Correct |
14 ms |
6784 KB |
Output is correct |
26 |
Correct |
18 ms |
6784 KB |
Output is correct |
27 |
Correct |
11 ms |
6784 KB |
Output is correct |
28 |
Correct |
10 ms |
6784 KB |
Output is correct |
29 |
Correct |
12 ms |
6784 KB |
Output is correct |
30 |
Correct |
10 ms |
6784 KB |
Output is correct |
31 |
Correct |
10 ms |
6784 KB |
Output is correct |
32 |
Correct |
10 ms |
6784 KB |
Output is correct |
33 |
Correct |
13 ms |
6912 KB |
Output is correct |
34 |
Correct |
12 ms |
6912 KB |
Output is correct |
35 |
Correct |
332 ms |
7680 KB |
Output is correct |
36 |
Correct |
48 ms |
6876 KB |
Output is correct |
37 |
Correct |
749 ms |
7496 KB |
Output is correct |
38 |
Correct |
668 ms |
7800 KB |
Output is correct |
39 |
Correct |
784 ms |
7856 KB |
Output is correct |
40 |
Correct |
893 ms |
7800 KB |
Output is correct |
41 |
Correct |
932 ms |
7928 KB |
Output is correct |
42 |
Correct |
64 ms |
7676 KB |
Output is correct |
43 |
Correct |
65 ms |
7668 KB |
Output is correct |
44 |
Correct |
70 ms |
7684 KB |
Output is correct |
45 |
Correct |
30 ms |
7800 KB |
Output is correct |
46 |
Correct |
30 ms |
7808 KB |
Output is correct |
47 |
Execution timed out |
1064 ms |
8064 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |