# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883271 | tosivanmak | Aliens (IOI07_aliens) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
bool ck(pair<ll,ll>coordinate, ll n){
if(coordinate.x>n||coordinate.y>n||coordinate.x<1||coordinate.y<1){
return false;
}
return examine(coordinate.x,coordinate.y);
}
struct co{
ll x,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})){
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})){
ans.y=middle.y+2*M;
}
else{
ans.y=middle.y;
}
}
else{
ans.y=middle.y-2*M;
}
solution(ans.x,ans.y);
}