Submission #1285380

#TimeUsernameProblemLanguageResultExecution timeMemory
1285380kerem산악 구조대 (JOI13_mountain)C++20
80 / 100
7 ms584 KiB
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
//~ #define sp << " " <<

int target;
pair<int,int> calc(int x,int y,int n,int m,int tx,int ty){
	//~ cout << x sp y sp n sp m sp tx sp ty << endl;
	if(n==0 || m==0) return make_pair(0,0);
	if(n==1){
		for(int i=0;i<m;y+=ty,i++)
			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,i++)
			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,CS,-1,-1));
	p=max(p,calc(RS,CS,R-RS+1,CS,1,-1));
	p=max(p,calc(RS,CS,RS,C-CS+1,-1,1));
	p=max(p,calc(RS,CS,R-RS+1,C-CS+1,1,1));
	Pinpoint(p.first,p.second);
}
/*
4 5 3 2 8
 5 26 16  7  1
17 27 20  8  2
25 30 28 10  3
23 29 24 13 12
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...