#include <bits/stdc++.h>
#define all(aa) aa.begin(), aa.end()
#define pb push_back
#define endl ("\n")
typedef long long ll;
using namespace std;
const ll INF (1000000000000000);
const int maxn = 2005, maxm = 2005;
int n, m, target, pos, sped;
bool vis[maxn][maxn];
vector<int> v[maxn];
queue<array<int, 3>> q;
void pushq(int u, int s, int dst){
if(u - s >= 0) q.push({u - s, s, dst});
if(u + s < n) q.push({u+s, s, dst});
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
int b, p;
cin >> b >> p;
if(i == 0) sped = p, pos = b;
if(i != 1) v[b].pb(p);
else target = b;
}
for(int i = 0; i < n; i++){
sort(all(v[i]));
v[i].resize(unique(all(v[i])) - v[i].begin());
}
q.push({pos, sped, 0});
while(!q.empty()){
auto [u, s, dst] = q.front(); q.pop();
if(target == u) cout << dst, exit(0);
if(vis[u][s])
continue;
vis[u][s] = 1;
for(int sp : v[u])
pushq(u, sp, dst+1);
pushq(u, s, dst+1);
}
cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
412 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
1624 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
3420 KB |
Output is correct |
24 |
Correct |
4 ms |
4188 KB |
Output is correct |
25 |
Correct |
2 ms |
1628 KB |
Output is correct |
26 |
Correct |
3 ms |
4184 KB |
Output is correct |
27 |
Correct |
3 ms |
4188 KB |
Output is correct |
28 |
Correct |
3 ms |
4388 KB |
Output is correct |
29 |
Correct |
4 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4188 KB |
Output is correct |
31 |
Correct |
3 ms |
4184 KB |
Output is correct |
32 |
Correct |
3 ms |
4188 KB |
Output is correct |
33 |
Correct |
7 ms |
5408 KB |
Output is correct |
34 |
Correct |
8 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
3476 KB |
Output is correct |
24 |
Correct |
3 ms |
4188 KB |
Output is correct |
25 |
Correct |
2 ms |
1624 KB |
Output is correct |
26 |
Correct |
3 ms |
4188 KB |
Output is correct |
27 |
Correct |
3 ms |
4188 KB |
Output is correct |
28 |
Correct |
4 ms |
4444 KB |
Output is correct |
29 |
Correct |
4 ms |
4384 KB |
Output is correct |
30 |
Correct |
2 ms |
4188 KB |
Output is correct |
31 |
Correct |
3 ms |
4188 KB |
Output is correct |
32 |
Correct |
3 ms |
4188 KB |
Output is correct |
33 |
Correct |
7 ms |
5528 KB |
Output is correct |
34 |
Correct |
8 ms |
5464 KB |
Output is correct |
35 |
Correct |
13 ms |
4276 KB |
Output is correct |
36 |
Correct |
2 ms |
1116 KB |
Output is correct |
37 |
Correct |
9 ms |
4188 KB |
Output is correct |
38 |
Correct |
12 ms |
3164 KB |
Output is correct |
39 |
Correct |
11 ms |
856 KB |
Output is correct |
40 |
Correct |
13 ms |
1368 KB |
Output is correct |
41 |
Correct |
13 ms |
2136 KB |
Output is correct |
42 |
Correct |
12 ms |
4444 KB |
Output is correct |
43 |
Correct |
12 ms |
4592 KB |
Output is correct |
44 |
Correct |
11 ms |
4444 KB |
Output is correct |
45 |
Correct |
161 ms |
68888 KB |
Output is correct |
46 |
Correct |
153 ms |
69808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
500 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
756 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
352 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
3 ms |
3420 KB |
Output is correct |
24 |
Correct |
4 ms |
4096 KB |
Output is correct |
25 |
Correct |
2 ms |
1628 KB |
Output is correct |
26 |
Correct |
3 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4440 KB |
Output is correct |
28 |
Correct |
5 ms |
4440 KB |
Output is correct |
29 |
Correct |
4 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4188 KB |
Output is correct |
31 |
Correct |
3 ms |
4188 KB |
Output is correct |
32 |
Correct |
3 ms |
4216 KB |
Output is correct |
33 |
Correct |
6 ms |
5468 KB |
Output is correct |
34 |
Correct |
6 ms |
5356 KB |
Output is correct |
35 |
Correct |
12 ms |
4444 KB |
Output is correct |
36 |
Correct |
2 ms |
1112 KB |
Output is correct |
37 |
Correct |
11 ms |
4440 KB |
Output is correct |
38 |
Correct |
13 ms |
3676 KB |
Output is correct |
39 |
Correct |
12 ms |
1120 KB |
Output is correct |
40 |
Correct |
12 ms |
1584 KB |
Output is correct |
41 |
Correct |
12 ms |
2396 KB |
Output is correct |
42 |
Correct |
11 ms |
4664 KB |
Output is correct |
43 |
Correct |
11 ms |
4776 KB |
Output is correct |
44 |
Correct |
12 ms |
4700 KB |
Output is correct |
45 |
Correct |
145 ms |
69012 KB |
Output is correct |
46 |
Correct |
140 ms |
68884 KB |
Output is correct |
47 |
Runtime error |
11 ms |
1884 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |