#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
int target;
pair<int,int> calc(int x,int y,int n,int m,int tx,int ty){
if(n==1){
for(int i=0;i<m;y+=ty)
if(Measure(x,y)==target)
return make_pair(x,y);
return make_pair(0,0);
}
if(m==1){
for(int i=0;i<n;x+=tx)
if(Measure(x,y)==target)
return make_pair(x,y);
return make_pair(0,0);
}
int l=0,r=min(n,m)-1;
while(l<r){
int mid=(l+r+1)/2;
int d=Measure(x+tx*mid,y+ty*mid);
if(d==target) return make_pair(x+tx*mid,y+ty*mid);
if(d<target) r=mid-1;
else l=mid;
}
l++;
return max(calc(x+tx*l,y,n-l,l,tx,ty),calc(x,y+ty*l,l,m-l,tx,ty));
}
void Rescue(int R, int C, int RS, int CS, int X){
target=X;
pair<int,int> p={0,0};
p=max(p,calc(RS,CS,RS-1,CS-1,-1,-1));
p=max(p,calc(RS,CS,R-RS,CS-1,1,-1));
p=max(p,calc(RS,CS,RS-1,C-CS,-1,1));
p=max(p,calc(RS,CS,R-RS,C-CS,1,1));
Pinpoint(p.first,p.second);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |