#include <iostream>
#include <set>
#include <queue>
#include <vector>
using namespace std;
vector<set<int>> v(1000000);
int n, m, q;
int M;
void bf(int k, int l) {
//int viz[20001]{0};
vector<int> viz(2*n);
queue<int> q;
viz[k] = 1;
q.push(k);
bool E = 1;
while (!q.empty() && E) {
for (auto m : v[q.front()]) {
if (!viz[m]) {
q.push(m);
viz[m] = viz[q.front()] + 1;
if (m == l) {
cout << viz[l] - 1 << '\n';
return;
}
}
}
q.pop();
}
cout << viz[l] - 1 << '\n';
}
int main() {
cin >> n >> m >> q;
for (int i = 0; i < m; ++i) {
cin >> M;
v[M].insert(M+n);
v[M+n].insert(M);
}
for (int i = 0; i < 2*n; ++i) {
if (i == 0)
v[i].insert(2*n-1);
if (i == 2*n-1)
v[i].insert(0);
if (i < 2*n-1) v[i].insert(i+1);
if (i > 0) v[i].insert(i-1);
}
for (int i = 0; i < q; ++i) {
int a, b;
cin >> a >> b;
bf(a, b);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
47440 KB |
Output is correct |
2 |
Correct |
52 ms |
47416 KB |
Output is correct |
3 |
Correct |
66 ms |
47592 KB |
Output is correct |
4 |
Correct |
24 ms |
47448 KB |
Output is correct |
5 |
Execution timed out |
2076 ms |
66984 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47448 KB |
Output is correct |
2 |
Correct |
26 ms |
47452 KB |
Output is correct |
3 |
Correct |
28 ms |
47444 KB |
Output is correct |
4 |
Correct |
24 ms |
47192 KB |
Output is correct |
5 |
Correct |
30 ms |
47448 KB |
Output is correct |
6 |
Correct |
28 ms |
47196 KB |
Output is correct |
7 |
Correct |
28 ms |
47452 KB |
Output is correct |
8 |
Correct |
32 ms |
47608 KB |
Output is correct |
9 |
Correct |
34 ms |
47452 KB |
Output is correct |
10 |
Correct |
28 ms |
47452 KB |
Output is correct |
11 |
Correct |
32 ms |
47448 KB |
Output is correct |
12 |
Correct |
36 ms |
47452 KB |
Output is correct |
13 |
Correct |
32 ms |
47452 KB |
Output is correct |
14 |
Correct |
24 ms |
47448 KB |
Output is correct |
15 |
Correct |
26 ms |
47452 KB |
Output is correct |
16 |
Correct |
22 ms |
47196 KB |
Output is correct |
17 |
Correct |
24 ms |
47196 KB |
Output is correct |
18 |
Correct |
23 ms |
47416 KB |
Output is correct |
19 |
Correct |
22 ms |
47336 KB |
Output is correct |
20 |
Correct |
23 ms |
47196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47448 KB |
Output is correct |
2 |
Correct |
26 ms |
47452 KB |
Output is correct |
3 |
Correct |
28 ms |
47444 KB |
Output is correct |
4 |
Correct |
24 ms |
47192 KB |
Output is correct |
5 |
Correct |
30 ms |
47448 KB |
Output is correct |
6 |
Correct |
28 ms |
47196 KB |
Output is correct |
7 |
Correct |
28 ms |
47452 KB |
Output is correct |
8 |
Correct |
32 ms |
47608 KB |
Output is correct |
9 |
Correct |
34 ms |
47452 KB |
Output is correct |
10 |
Correct |
28 ms |
47452 KB |
Output is correct |
11 |
Correct |
32 ms |
47448 KB |
Output is correct |
12 |
Correct |
36 ms |
47452 KB |
Output is correct |
13 |
Correct |
32 ms |
47452 KB |
Output is correct |
14 |
Correct |
24 ms |
47448 KB |
Output is correct |
15 |
Correct |
26 ms |
47452 KB |
Output is correct |
16 |
Correct |
22 ms |
47196 KB |
Output is correct |
17 |
Correct |
24 ms |
47196 KB |
Output is correct |
18 |
Correct |
23 ms |
47416 KB |
Output is correct |
19 |
Correct |
22 ms |
47336 KB |
Output is correct |
20 |
Correct |
23 ms |
47196 KB |
Output is correct |
21 |
Correct |
24 ms |
47448 KB |
Output is correct |
22 |
Correct |
27 ms |
47452 KB |
Output is correct |
23 |
Correct |
27 ms |
47452 KB |
Output is correct |
24 |
Correct |
31 ms |
47184 KB |
Output is correct |
25 |
Correct |
26 ms |
47448 KB |
Output is correct |
26 |
Correct |
25 ms |
47440 KB |
Output is correct |
27 |
Correct |
29 ms |
47448 KB |
Output is correct |
28 |
Correct |
32 ms |
47456 KB |
Output is correct |
29 |
Correct |
35 ms |
47452 KB |
Output is correct |
30 |
Correct |
32 ms |
47448 KB |
Output is correct |
31 |
Correct |
33 ms |
47452 KB |
Output is correct |
32 |
Correct |
34 ms |
47452 KB |
Output is correct |
33 |
Correct |
29 ms |
47452 KB |
Output is correct |
34 |
Correct |
20 ms |
47452 KB |
Output is correct |
35 |
Correct |
22 ms |
47480 KB |
Output is correct |
36 |
Correct |
21 ms |
47192 KB |
Output is correct |
37 |
Runtime error |
61 ms |
95572 KB |
Execution killed with signal 11 |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
95568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
47440 KB |
Output is correct |
2 |
Correct |
52 ms |
47416 KB |
Output is correct |
3 |
Correct |
66 ms |
47592 KB |
Output is correct |
4 |
Correct |
24 ms |
47448 KB |
Output is correct |
5 |
Execution timed out |
2076 ms |
66984 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |