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;
#include "grader.h"
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
void Rescue(int R, int C, int RS, int CS, int X) {
    vector<vector<pair<int, int> > > group;
    for (int i = 1; i <= R; ++i) {
        for (int j = 1; j <= C; ++j) {
            int dist = abs(i - RS) + abs(j - CS);
            while (sz(group) <= dist) group.emplace_back(vector<pair<int, int> >() );
            group[dist].emplace_back(i, j);
        }
    }
    int l = 0, r = sz(group) - 1;
    while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (Measure(group[mid].back().first, group[mid].back().second) >= X) l = mid;
        else r = mid - 1;
    }
    for (const auto &i : group[l]) {
        if (Measure(i.first, i.second) == X) {
            Pinpoint(i.first, i.second);
            return ;
        }
    }
    for (const auto &i : group[l + 1]) {
        if (Measure(i.first, i.second) == X) {
            Pinpoint(i.first, i.second);
            return ;
        }
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |