#include <bits/stdc++.h>
using namespace std;
int n,M,Q;
set <int> s;
int stanga(int x,int y)
{
if(x<y)
return 2*n-y+x;
else
return x-y;
}
int dreapta(int x,int y)
{
if(x>y)
return 2*n-x+y;
else
return y-x;
}
int shc(int x, int y)
{
auto vst=distance(s.begin(), s.upper_bound(x));
int vdr=*s.lower_bound(x);
cout<<'\n';
cout<<vst<<' '<<vdr<<'\n';
if(vst==0)
vst=*s.end();
if(vdr==s.size())
vdr=*s.begin();
cout<<vst<<' '<<vdr<<'\n';
return 0;
int dist1=stanga(x,vst)+stanga(vst,y);
int dist2=stanga(x,vst)+dreapta(vst,y);
int dist3=dreapta(x,vdr)+stanga(vdr,y);
int dist4=dreapta(x,vdr)+dreapta(vdr,y);
return min(dist1,min(dist2,min(dist3,dist4)));
}
int main()
{
cin>>n>>M>>Q;
for(int i=1;i<=M;++i)
{
int x;
cin>>x;
s.insert(abs(2*n-x));
s.insert(abs(x));
}
for(int i=1;i<=Q;++i)
{
int a,b;
cin>>a>>b;
cout<<shc(a,b);
cout<<'\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'int shc(int, int)':
Main.cpp:27:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if(vdr==s.size())
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |