#include<bits/stdc++.h>
using namespace std;
#define ll long long
#ifdef __cplusplus
extern "C" {
#endif
int examine(int X, int Y);
void solution(int XC, int YC);
void findCenter(int N, int X0, int Y0);
#ifdef __cplusplus
}
#endif
// TODO: global variables can be declared here
ll find_coor_x(ll N, ll X0, ll Y0, ll mul){
ll curx=X0,cury=Y0;
bool ok=true;
ll searchl,searchr;
for(int i=0;i<=29;i++){
if(curx>N||!ok||curx<1){
searchl=curx-(((1<<(i-1)))*mul);
searchr=curx;
if(searchr>N){
searchr=N;
}
break;
}
curx+=((1<<i)*mul);
ok=examine(curx,cury);
}
if(mul==-1){
swap(searchl,searchr);
}
while(searchl<=searchr){
if(searchl==searchr){
break;
}
else if(searchl==searchr-1){
if(mul==-1){
if(examine(searchl,cury)){
searchr=searchl;
}
else{
searchl=searchr;
}
}
else{
if(examine(searchr,cury)){
searchl=searchr;
}
else{
searchr=searchl;
break;
}
}
break;
}
else{
ll mid=(searchl+searchr)>>1;
if(mul==-1){
if(examine(mid,cury)){
searchr=mid;
}
else{
searchl=mid;
}
}
else{
if(examine(mid,cury)){
searchl=mid;
}
else{
searchr=mid;
}
}
}
}
return searchl;
}
ll find_coor_y(ll N, ll X0, ll Y0, ll mul){
ll curx=X0,cury=Y0;
bool ok=true;
ll searchl,searchr;
for(int i=0;i<=29;i++){
if(cury>N||!ok||cury<1){
searchl=cury-(((1<<(i-1)))*mul);
searchr=cury;
if(searchr>N){
searchr=N;
}
break;
}
cury+=((1<<i)*mul);
ok=examine(curx,cury);
}
if(mul==-1){
swap(searchl,searchr);
}
while(searchl<=searchr){
if(searchl==searchr){
break;
}
else if(searchl==searchr-1){
if(mul==-1){
if(examine(curx,searchl)){
searchr=searchl;
}
else{
searchl=searchr;
}
}
else{
if(examine(curx,searchr)){
searchl=searchr;
}
else{
searchr=searchl;
break;
}
}
break;
}
else{
ll mid=(searchl+searchr)>>1;
if(mul==-1){
if(examine(curx,mid)){
searchr=mid;
}
else{
searchl=mid;
}
}
else{
if(examine(curx,mid)){
searchl=mid;
}
else{
searchr=mid;
}
}
}
}
return searchl;
}
struct co{
ll x,y;
};
bool ck(co coordinate, ll n){
if(coordinate.x>n||coordinate.y>n||coordinate.x<1||coordinate.y<1){
return false;
}
return examine(coordinate.x,coordinate.y);
}
void findCenter(int N, int X0, int Y0) {
// TODO: implementation
ll xl=find_coor_x(N,X0,Y0,-1);
ll xr=find_coor_x(N,X0,Y0,1);
ll yl=find_coor_y(N,X0,Y0,-1);
ll yr=find_coor_y(N,X0,Y0,1);
co middle={(xl+xr)/2,(yl+yr)/2};
ll M=(xr-xl+1);
co ans;
if(ck({middle.x+2*M,middle.y},N)){
if(ck({middle.x+4*M,middle.y},N)){
ans={middle.x+2*M,middle.y};
}
else{
ans=middle;
}
}
else{
ans={middle.x-2*M,middle.y};
}
if(ck({middle.x,middle.y+2*M},N)){
if(ck({middle.x,middle.y+4*M},N)){
ans.y=middle.y+2*M;
}
else{
ans.y=middle.y;
}
}
else{
ans.y=middle.y-2*M;
}
solution(ans.x,ans.y);
}
Compilation message
aliens.cpp: In function 'long long int find_coor_x(long long int, long long int, long long int, long long int)':
aliens.cpp:40:31: warning: 'searchr' may be used uninitialized in this function [-Wmaybe-uninitialized]
40 | else if(searchl==searchr-1){
| ~~~~~~~^~
aliens.cpp: In function 'long long int find_coor_y(long long int, long long int, long long int, long long int)':
aliens.cpp:105:31: warning: 'searchr' may be used uninitialized in this function [-Wmaybe-uninitialized]
105 | else if(searchl==searchr-1){
| ~~~~~~~^~
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /tmp/ccAjJwW7.o: in function `find_coor_x(long long, long long, long long, long long)':
aliens.cpp:(.text+0x50): undefined reference to `examine'
/usr/bin/ld: aliens.cpp:(.text+0xc1): undefined reference to `examine'
/usr/bin/ld: aliens.cpp:(.text+0xf0): undefined reference to `examine'
/usr/bin/ld: aliens.cpp:(.text+0x126): undefined reference to `examine'
/usr/bin/ld: aliens.cpp:(.text+0x13c): undefined reference to `examine'
/usr/bin/ld: /tmp/ccAjJwW7.o:aliens.cpp:(.text+0x1a0): more undefined references to `examine' follow
/usr/bin/ld: /tmp/ccAjJwW7.o: in function `findCenter':
aliens.cpp:(.text+0x46b): undefined reference to `solution'
collect2: error: ld returned 1 exit status