結果

問題 No.3680 セグメント釣り
コンテスト
ユーザー 👑 loop0919
提出日時 2026-06-22 22:57:02
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 55 ms / 2,000 ms
+ 614µs
コード長 782 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,893 ms
コンパイル使用メモリ 331,612 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 12:31:24
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll INF = 2'000'000'000'000'000'000;
constexpr int LIMIT = 60;

ll pow_2(int e) {
    return 1LL << e;
}

ll solve(ll s_x, ll s_y, ll t_x, ll t_y) {
    if (max(s_y, t_y) >= LIMIT) {
        return abs(s_y - t_y);
    }

    ll ans = INF;
    for (int h = max(s_y, t_y); h <= LIMIT; h++) {
        ll dist_x = abs(s_x / pow_2(h) - t_x / pow_2(h));
        ll dist_y = (h - s_y) +  (h - t_y);

        ans = min(ans, dist_x + dist_y);
    }

    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        ll s_x, s_y, t_x, t_y;
        cin >> s_x >> s_y >> t_x >> t_y;
        cout << solve(s_x, s_y, t_x, t_y) << '\n';
    }
}
0