結果

問題 No.3520 L1等距離点
コンテスト
ユーザー nono00
提出日時 2026-05-01 22:12:02
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,721 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,797 ms
コンパイル使用メモリ 333,236 KB
実行使用メモリ 30,064 KB
平均クエリ数 6.94
最終ジャッジ日時 2026-05-01 22:12:27
合計ジャッジ時間 7,091 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep2(i, n) for (ll i = n; i-- > 0;)
#define rrep3(i, r, l) for (ll i = (r); i-- > (l);)
#define overload(a, b, c, d, ...) d
#define rep(...) overload(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rrep(...) overload(__VA_ARGS__, rrep3, rrep2)(__VA_ARGS__)
#define all(x) begin(x), end(x)
bool chmin(auto& lhs, auto rhs) {
    return lhs > rhs ? lhs = rhs, 1 : 0;
}
bool chmax(auto& lhs, auto rhs) {
    return lhs < rhs ? lhs = rhs, 1 : 0;
}
struct IOIO {
    IOIO() {
        std::cin.tie(0)->sync_with_stdio(0);
    }
} ioio;

struct Point {
    int x, y;
};

int dist(Point lhs, Point rhs) {
    return abs(lhs.x - rhs.x) + abs(lhs.y - rhs.y);
}

#ifdef DEBUG

struct Judge {
    int T;
    Point s, g;
    vector<Point> path;
    Judge() {}
    tuple<int, Point, Point> input() {
        mt19937 mt(random_device{}());
        T = mt() % 100 + 1;
        s = {mt() % 100, mt() % 100};
        path.push_back(s);
        g = s;
        rep(_, T) {
            if (mt() % 2) {
                if (mt() % 2) {
                    g.x += mt() % 2 ? 1 : -1;
                } else {
                    g.y += mt() % 2 ? 1 : -1;
                }
            }
            path.push_back(g);
        }
        return {T, s, g};
    }
    Point ask(int t) {
        cerr << "ask " << t << endl;
        return path[t];
    }
    void answer(optional<int> ans) {
        cerr << "maybe ok! w";
    }
};

#else

struct Judge {
    Judge() {}
    tuple<int, Point, Point> input() {
        int T;
        Point s, g;
        cin >> T >> s.x >> s.y >> g.x >> g.y;
        return {T, s, g};
    }
    Point ask(int t) {
        cout << "? " << t << endl;
        int x, y;
        cin >> x >> y;
        return Point{x, y};
    }
    void answer(optional<int> ans) {
        if (ans)
            cout << "! " << *ans << endl;
        else
            cout << "! NaN" << endl;
        assert(ans);
    }
};

#endif

void solve() {
#ifdef DEBUG
    Judge judge;
#else
    Judge judge;
#endif
    auto [T, s, g] = judge.input();
    int L = 0;
    int R = T;
    while (R - L > 1) {
        int M = (L + R) / 2;
        auto res = judge.ask(M);
        if (dist(s, res) <= dist(g, res)) {
            L = M;
        } else {
            R = M;
        }
    }
    judge.answer(L);
}

int main() {
    int t = 1;
    //  cin >> t;
    while (t--) solve();
}
0