#include <bits/stdc++.h>
using namespace std;
int n;
int odl(int a, int b){
int wynik=abs(a-b);
wynik = min(wynik, (2*n)-max(a,b)+min(a,b));
return wynik;
}
int main()
{
int m,q,a,b;
cin >> n >> m >> q;
vector<int> pary(0);
for (int i=0; i<m; i++){
cin >> a;
pary.push_back(a);
pary.push_back(a+n);
}
sort(pary.begin(),pary.end());
//for (auto [i_1,i_2] : pary) cout << i_1 << " " << i_2 << endl;
//liczymy pierwszy na lewo
int akt_para = 1;
int akt_idx = pary[0];
vector<int> lewo(2*n);
for (int i=0; i<2*n; i++){
if (akt_para < pary.size() && pary[akt_para]==akt_idx){
akt_para++;
}
//cout << akt_idx << endl;
lewo[akt_idx] = pary[akt_para-1];
//cout << akt_idx << " " << lewo[akt_idx] << endl;
akt_idx = (akt_idx+1)%(2*n);
}
//Liczymy pierwszy na prawo
akt_para = (2*m)-2;
akt_idx = pary[(2*m)-1];
vector<int> prawo(2*n);
for (int i=0; i<2*n; i++){
//cout << "DUPA " << (akt_idx-1+(2*n))%(2*n) << " " << akt_idx << endl;
if (akt_para >=0 && pary[akt_para]==akt_idx){
akt_para--;
}
prawo[akt_idx] = pary[akt_para+1];
//cout << akt_idx << " " << prawo[akt_idx] << endl;
akt_idx = (akt_idx-1+(2*n))%(2*n);
}
for (int i=0; i<q; i++){
cin >> a >> b;
int wynik = odl(a,b);
wynik = min(wynik, 1+odl(a,prawo[a]) + odl(((prawo[a]+n)%(2*n)), b));
wynik = min(wynik, 1+odl(a,lewo[a]) + odl(((lewo[a]+n)%(2*n)), b));
cout << wynik << endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (akt_para < pary.size() && pary[akt_para]==akt_idx){
| ~~~~~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
348 KB |
Output is correct |
2 |
Correct |
21 ms |
348 KB |
Output is correct |
3 |
Correct |
21 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
30 ms |
2104 KB |
Output is correct |
6 |
Runtime error |
430 ms |
1048580 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
388 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
103 ms |
105912 KB |
Output is correct |
38 |
Correct |
104 ms |
107088 KB |
Output is correct |
39 |
Correct |
87 ms |
89936 KB |
Output is correct |
40 |
Correct |
125 ms |
130128 KB |
Output is correct |
41 |
Correct |
92 ms |
93876 KB |
Output is correct |
42 |
Correct |
148 ms |
151896 KB |
Output is correct |
43 |
Correct |
48 ms |
49244 KB |
Output is correct |
44 |
Correct |
145 ms |
147532 KB |
Output is correct |
45 |
Correct |
152 ms |
156756 KB |
Output is correct |
46 |
Correct |
152 ms |
156756 KB |
Output is correct |
47 |
Correct |
153 ms |
156784 KB |
Output is correct |
48 |
Correct |
153 ms |
156756 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
299 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
348 KB |
Output is correct |
2 |
Correct |
21 ms |
348 KB |
Output is correct |
3 |
Correct |
21 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
30 ms |
2104 KB |
Output is correct |
6 |
Runtime error |
430 ms |
1048580 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |