結果

問題 No.3375 Binary Grid
コンテスト
ユーザー 👑 loop0919
提出日時 2025-10-09 00:32:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 2,769 ms
コンパイル使用メモリ 275,708 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-21 20:50:16
合計ジャッジ時間 4,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;

ull calc(ull r, ull c) {
    for (int i = (int) c + 1; i < bit_width(r); i++) {
        if (((r >> i) & 1) == 0) {
            ull nr = r & ~((1LL << i) - 1) | (1LL << i);
            ull nc = i;
            return max(nr - r, nc - c) + calc(nr, nc);
        }
    }
    return r - 1;
}

void solve() {
    ull R, C;
    cin >> R >> C;

    cout << calc(R, C - 1) << "\n";
}

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

    int T;
    cin >> T;

    while (T--) solve();
}
0