이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
void Rescue(int R, int C, int RS, int CS, int X) {
int upper = max(RS - 1, R - RS) + max(CS - 1, C - CS), lower = 0;
vector<vector<pair<int,int>>> points(upper + 1);
for (int i = 1; i <= R; ++i) {
for (int j = 1; j <= C; ++j) {
points[abs(i - RS) + abs(j - CS)].emplace_back(i, j);
}
}
auto calc = [&](int d) {
int res = 1e9;
for (auto [i, j] : points[d]) {
if (j <= 0 || j > C) continue;
int H = Measure(i, j);
if (H == X) {
Pinpoint(i, j);
return -1;
}
res = min(res, H);
}
return res;
};
if (calc(upper) == -1) return;
if (calc(lower) == -1) return;
while (upper - lower > 1) {
int mid = (upper + lower) / 2;
int H = calc(mid);
if (H == -1) return;
(H >= X ? lower : upper) = mid;
}
if (calc(lower) == -1) return;
if (calc(upper) == -1) return;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |