#include <bits/stdc++.h>
using namespace std;
struct pii {
int x, i;
bool operator<(const pii b) const { return x>b.x; }
};
int main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
int N, M, st=0, ed=-1;
cin>>N>>M;
vector<int> D(N, INT_MAX);
vector<vector<int>> A(N);
vector<bitset<30208>> V(N);
for(int i=0; i<M; i++) {
int x, m;
cin>>x>>m;
if(i==0) st=x;
else if(i==1) ed=x;
if(max(x, N-1-x)>=m && !V[x][m]) A[x].push_back(m), V[x][m]=true;
}
priority_queue<pii> q;
q.push({0, st}); D[st]=0;
while(q.size()) {
auto[n,x]=q.top(); q.pop();
if(D[x]!=n) continue;
if(x==ed) { cout<<n; return 0; }
for(int m:A[x]) {
for(int i=x+m, d=n+1; i<N; i+=m, d++) if(d<D[i]) {
D[i]=d, q.push({d, i});
if(V[i][m]) break;
V[i][m]=true;
}
for(int i=x-m, d=n+1; i>=0; i-=m, d++) if(d<D[i]) {
D[i]=d, q.push({d, i});
if(V[i][m]) break;
V[i][m]=true;
}
}
}
cout<<-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
760 KB |
Output is correct |
11 |
Correct |
6 ms |
764 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
760 KB |
Output is correct |
15 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
764 KB |
Output is correct |
11 |
Correct |
5 ms |
760 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
764 KB |
Output is correct |
14 |
Correct |
6 ms |
760 KB |
Output is correct |
15 |
Correct |
5 ms |
760 KB |
Output is correct |
16 |
Correct |
5 ms |
1144 KB |
Output is correct |
17 |
Correct |
8 ms |
3192 KB |
Output is correct |
18 |
Correct |
8 ms |
6908 KB |
Output is correct |
19 |
Correct |
8 ms |
7800 KB |
Output is correct |
20 |
Correct |
11 ms |
7800 KB |
Output is correct |
21 |
Correct |
7 ms |
1784 KB |
Output is correct |
22 |
Correct |
8 ms |
7032 KB |
Output is correct |
23 |
Correct |
9 ms |
6264 KB |
Output is correct |
24 |
Correct |
10 ms |
7416 KB |
Output is correct |
25 |
Correct |
9 ms |
7800 KB |
Output is correct |
26 |
Correct |
17 ms |
7800 KB |
Output is correct |
27 |
Correct |
9 ms |
7800 KB |
Output is correct |
28 |
Correct |
10 ms |
7800 KB |
Output is correct |
29 |
Correct |
10 ms |
8184 KB |
Output is correct |
30 |
Correct |
9 ms |
7928 KB |
Output is correct |
31 |
Correct |
9 ms |
7928 KB |
Output is correct |
32 |
Correct |
10 ms |
7928 KB |
Output is correct |
33 |
Correct |
12 ms |
8056 KB |
Output is correct |
34 |
Correct |
11 ms |
8056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
760 KB |
Output is correct |
11 |
Correct |
5 ms |
760 KB |
Output is correct |
12 |
Correct |
6 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
6 ms |
760 KB |
Output is correct |
15 |
Correct |
5 ms |
764 KB |
Output is correct |
16 |
Correct |
5 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
3196 KB |
Output is correct |
18 |
Correct |
9 ms |
6908 KB |
Output is correct |
19 |
Correct |
9 ms |
7800 KB |
Output is correct |
20 |
Correct |
11 ms |
7800 KB |
Output is correct |
21 |
Correct |
5 ms |
1788 KB |
Output is correct |
22 |
Correct |
8 ms |
7032 KB |
Output is correct |
23 |
Correct |
9 ms |
6264 KB |
Output is correct |
24 |
Correct |
9 ms |
7416 KB |
Output is correct |
25 |
Correct |
9 ms |
7800 KB |
Output is correct |
26 |
Correct |
9 ms |
7800 KB |
Output is correct |
27 |
Correct |
9 ms |
7800 KB |
Output is correct |
28 |
Correct |
9 ms |
7848 KB |
Output is correct |
29 |
Correct |
10 ms |
7928 KB |
Output is correct |
30 |
Correct |
9 ms |
7928 KB |
Output is correct |
31 |
Correct |
10 ms |
7932 KB |
Output is correct |
32 |
Correct |
9 ms |
7928 KB |
Output is correct |
33 |
Correct |
10 ms |
8056 KB |
Output is correct |
34 |
Correct |
12 ms |
8056 KB |
Output is correct |
35 |
Correct |
14 ms |
5880 KB |
Output is correct |
36 |
Correct |
8 ms |
4472 KB |
Output is correct |
37 |
Correct |
13 ms |
7800 KB |
Output is correct |
38 |
Correct |
16 ms |
8056 KB |
Output is correct |
39 |
Correct |
16 ms |
7928 KB |
Output is correct |
40 |
Correct |
16 ms |
8056 KB |
Output is correct |
41 |
Correct |
17 ms |
8056 KB |
Output is correct |
42 |
Correct |
14 ms |
7800 KB |
Output is correct |
43 |
Correct |
16 ms |
7800 KB |
Output is correct |
44 |
Correct |
16 ms |
7800 KB |
Output is correct |
45 |
Correct |
16 ms |
8184 KB |
Output is correct |
46 |
Correct |
15 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
372 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
760 KB |
Output is correct |
11 |
Correct |
5 ms |
760 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
6 ms |
760 KB |
Output is correct |
15 |
Correct |
5 ms |
760 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
7 ms |
3192 KB |
Output is correct |
18 |
Correct |
8 ms |
6904 KB |
Output is correct |
19 |
Correct |
9 ms |
7800 KB |
Output is correct |
20 |
Correct |
11 ms |
7928 KB |
Output is correct |
21 |
Correct |
6 ms |
1788 KB |
Output is correct |
22 |
Correct |
8 ms |
7032 KB |
Output is correct |
23 |
Correct |
9 ms |
6264 KB |
Output is correct |
24 |
Correct |
9 ms |
7416 KB |
Output is correct |
25 |
Correct |
9 ms |
7800 KB |
Output is correct |
26 |
Correct |
10 ms |
7800 KB |
Output is correct |
27 |
Correct |
10 ms |
7800 KB |
Output is correct |
28 |
Correct |
9 ms |
7800 KB |
Output is correct |
29 |
Correct |
10 ms |
8056 KB |
Output is correct |
30 |
Correct |
9 ms |
7928 KB |
Output is correct |
31 |
Correct |
10 ms |
7928 KB |
Output is correct |
32 |
Correct |
9 ms |
7928 KB |
Output is correct |
33 |
Correct |
10 ms |
8056 KB |
Output is correct |
34 |
Correct |
10 ms |
8056 KB |
Output is correct |
35 |
Correct |
14 ms |
5880 KB |
Output is correct |
36 |
Correct |
8 ms |
4472 KB |
Output is correct |
37 |
Correct |
14 ms |
7928 KB |
Output is correct |
38 |
Correct |
16 ms |
8056 KB |
Output is correct |
39 |
Correct |
15 ms |
7928 KB |
Output is correct |
40 |
Correct |
17 ms |
8184 KB |
Output is correct |
41 |
Correct |
17 ms |
8056 KB |
Output is correct |
42 |
Correct |
13 ms |
7800 KB |
Output is correct |
43 |
Correct |
14 ms |
7800 KB |
Output is correct |
44 |
Correct |
19 ms |
7928 KB |
Output is correct |
45 |
Correct |
18 ms |
8184 KB |
Output is correct |
46 |
Correct |
16 ms |
8184 KB |
Output is correct |
47 |
Correct |
44 ms |
47352 KB |
Output is correct |
48 |
Correct |
61 ms |
87160 KB |
Output is correct |
49 |
Correct |
59 ms |
95096 KB |
Output is correct |
50 |
Correct |
63 ms |
104440 KB |
Output is correct |
51 |
Correct |
84 ms |
113140 KB |
Output is correct |
52 |
Correct |
91 ms |
113140 KB |
Output is correct |
53 |
Correct |
71 ms |
112348 KB |
Output is correct |
54 |
Correct |
63 ms |
112248 KB |
Output is correct |
55 |
Correct |
68 ms |
112248 KB |
Output is correct |
56 |
Correct |
441 ms |
113008 KB |
Output is correct |
57 |
Correct |
66 ms |
112504 KB |
Output is correct |
58 |
Correct |
69 ms |
112248 KB |
Output is correct |
59 |
Correct |
68 ms |
112248 KB |
Output is correct |
60 |
Correct |
76 ms |
112248 KB |
Output is correct |
61 |
Correct |
71 ms |
112248 KB |
Output is correct |
62 |
Correct |
78 ms |
112504 KB |
Output is correct |
63 |
Correct |
87 ms |
113392 KB |
Output is correct |
64 |
Correct |
91 ms |
113396 KB |
Output is correct |
65 |
Correct |
97 ms |
114412 KB |
Output is correct |
66 |
Correct |
116 ms |
114416 KB |
Output is correct |
67 |
Correct |
101 ms |
114416 KB |
Output is correct |