#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int inf = 1e9, N = 30000;
int B[N], P[N];
vector<int> residents[N];
bitset<N> bl;
int dis[N];
vector<int> Q[N+1];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> B[i] >> P[i];
residents[B[i]].pb(i);
}
fill(dis, dis+m, inf);
for(int x: residents[B[0]]) Q[0].pb(x);
for(int d = 0; d <= N; d++) for(int nd: Q[d]){
if(nd == 1){
cout << d << "\n";
exit(0);
}
if(bl[nd]) continue;
bl[nd] = 1;
for(int i = B[nd]+P[nd], dd = d+1; i < n; i+=P[nd], dd++) for(int x: residents[i]) if(dd < dis[x]){
dis[x] = dd;
Q[dd].pb(x);
}
for(int i = B[nd]-P[nd], dd = d+1; i >= 0; i-=P[nd], dd++) for(int x: residents[i]) if(dd < dis[x]){
dis[x] = dd;
Q[dd].pb(x);
}
}
cout << "-1\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1744 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1744 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1740 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1744 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
2 ms |
1748 KB |
Output is correct |
14 |
Correct |
2 ms |
1864 KB |
Output is correct |
15 |
Correct |
2 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
2 ms |
1748 KB |
Output is correct |
14 |
Correct |
2 ms |
1752 KB |
Output is correct |
15 |
Correct |
2 ms |
1748 KB |
Output is correct |
16 |
Correct |
2 ms |
1748 KB |
Output is correct |
17 |
Correct |
2 ms |
1748 KB |
Output is correct |
18 |
Correct |
2 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1748 KB |
Output is correct |
20 |
Correct |
13 ms |
1920 KB |
Output is correct |
21 |
Correct |
2 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1748 KB |
Output is correct |
23 |
Correct |
1 ms |
1748 KB |
Output is correct |
24 |
Correct |
2 ms |
1748 KB |
Output is correct |
25 |
Correct |
2 ms |
1748 KB |
Output is correct |
26 |
Correct |
1 ms |
1748 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
1 ms |
1748 KB |
Output is correct |
30 |
Correct |
1 ms |
1748 KB |
Output is correct |
31 |
Correct |
2 ms |
1748 KB |
Output is correct |
32 |
Correct |
2 ms |
1744 KB |
Output is correct |
33 |
Correct |
2 ms |
1748 KB |
Output is correct |
34 |
Correct |
2 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1744 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
2 ms |
1744 KB |
Output is correct |
6 |
Correct |
1 ms |
1740 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
1 ms |
1748 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
2 ms |
1748 KB |
Output is correct |
13 |
Correct |
2 ms |
1748 KB |
Output is correct |
14 |
Correct |
2 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
1748 KB |
Output is correct |
16 |
Correct |
2 ms |
1748 KB |
Output is correct |
17 |
Correct |
2 ms |
1756 KB |
Output is correct |
18 |
Correct |
2 ms |
1748 KB |
Output is correct |
19 |
Correct |
2 ms |
1748 KB |
Output is correct |
20 |
Correct |
11 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1748 KB |
Output is correct |
23 |
Correct |
2 ms |
1744 KB |
Output is correct |
24 |
Correct |
2 ms |
1748 KB |
Output is correct |
25 |
Correct |
2 ms |
1748 KB |
Output is correct |
26 |
Correct |
1 ms |
1748 KB |
Output is correct |
27 |
Correct |
2 ms |
1756 KB |
Output is correct |
28 |
Correct |
2 ms |
1888 KB |
Output is correct |
29 |
Correct |
2 ms |
1748 KB |
Output is correct |
30 |
Correct |
1 ms |
1748 KB |
Output is correct |
31 |
Correct |
1 ms |
1748 KB |
Output is correct |
32 |
Correct |
1 ms |
1748 KB |
Output is correct |
33 |
Correct |
2 ms |
1748 KB |
Output is correct |
34 |
Correct |
2 ms |
1748 KB |
Output is correct |
35 |
Correct |
11 ms |
2772 KB |
Output is correct |
36 |
Correct |
3 ms |
1876 KB |
Output is correct |
37 |
Correct |
10 ms |
2652 KB |
Output is correct |
38 |
Correct |
12 ms |
3028 KB |
Output is correct |
39 |
Correct |
7 ms |
2644 KB |
Output is correct |
40 |
Correct |
9 ms |
2900 KB |
Output is correct |
41 |
Correct |
9 ms |
3028 KB |
Output is correct |
42 |
Correct |
5 ms |
2516 KB |
Output is correct |
43 |
Correct |
5 ms |
2648 KB |
Output is correct |
44 |
Correct |
215 ms |
2784 KB |
Output is correct |
45 |
Correct |
10 ms |
2952 KB |
Output is correct |
46 |
Correct |
10 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
2 ms |
1744 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
2 ms |
1748 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1748 KB |
Output is correct |
9 |
Correct |
2 ms |
1748 KB |
Output is correct |
10 |
Correct |
1 ms |
1744 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
2 ms |
1744 KB |
Output is correct |
14 |
Correct |
2 ms |
1748 KB |
Output is correct |
15 |
Correct |
1 ms |
1748 KB |
Output is correct |
16 |
Correct |
2 ms |
1752 KB |
Output is correct |
17 |
Correct |
2 ms |
1748 KB |
Output is correct |
18 |
Correct |
1 ms |
1748 KB |
Output is correct |
19 |
Correct |
2 ms |
1748 KB |
Output is correct |
20 |
Correct |
12 ms |
1916 KB |
Output is correct |
21 |
Correct |
2 ms |
1748 KB |
Output is correct |
22 |
Correct |
1 ms |
1748 KB |
Output is correct |
23 |
Correct |
1 ms |
1748 KB |
Output is correct |
24 |
Correct |
2 ms |
1752 KB |
Output is correct |
25 |
Correct |
2 ms |
1748 KB |
Output is correct |
26 |
Correct |
1 ms |
1748 KB |
Output is correct |
27 |
Correct |
1 ms |
1748 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
2 ms |
1748 KB |
Output is correct |
30 |
Correct |
1 ms |
1740 KB |
Output is correct |
31 |
Correct |
1 ms |
1748 KB |
Output is correct |
32 |
Correct |
1 ms |
1740 KB |
Output is correct |
33 |
Correct |
2 ms |
1748 KB |
Output is correct |
34 |
Correct |
2 ms |
1752 KB |
Output is correct |
35 |
Correct |
10 ms |
2772 KB |
Output is correct |
36 |
Correct |
3 ms |
1940 KB |
Output is correct |
37 |
Correct |
9 ms |
2648 KB |
Output is correct |
38 |
Correct |
14 ms |
3036 KB |
Output is correct |
39 |
Correct |
7 ms |
2644 KB |
Output is correct |
40 |
Correct |
8 ms |
2912 KB |
Output is correct |
41 |
Correct |
9 ms |
3156 KB |
Output is correct |
42 |
Correct |
6 ms |
2508 KB |
Output is correct |
43 |
Correct |
5 ms |
2644 KB |
Output is correct |
44 |
Correct |
211 ms |
2772 KB |
Output is correct |
45 |
Correct |
11 ms |
2904 KB |
Output is correct |
46 |
Correct |
12 ms |
2900 KB |
Output is correct |
47 |
Correct |
16 ms |
3148 KB |
Output is correct |
48 |
Correct |
6 ms |
2644 KB |
Output is correct |
49 |
Correct |
10 ms |
2648 KB |
Output is correct |
50 |
Correct |
5 ms |
2388 KB |
Output is correct |
51 |
Correct |
15 ms |
3840 KB |
Output is correct |
52 |
Correct |
17 ms |
3608 KB |
Output is correct |
53 |
Correct |
9 ms |
3312 KB |
Output is correct |
54 |
Correct |
1 ms |
1748 KB |
Output is correct |
55 |
Correct |
1 ms |
1744 KB |
Output is correct |
56 |
Execution timed out |
1075 ms |
4176 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |