結果

問題 No.3375 Binary Grid
コンテスト
ユーザー t98slider
提出日時 2025-11-21 22:54:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 195,876 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-11-21 22:54:54
合計ジャッジ時間 2,782 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:17: warning: ‘bt’ may be used uninitialized [-Wmaybe-uninitialized]
   39 |         while(x < bt){
      |               ~~^~~~
main.cpp:33:12: note: ‘bt’ was declared here
   33 |         ll bt;
      |            ^~

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        ll y, x;
        cin >> y >> x;
        x--;
        ll msb = __lg(y);
        if(msb == x){
            cout << y - 1 << '\n';
            continue;
        }
        ll ans = 0, c = x;
        while(y >> (c + 1) & 1) c++;
        if(c == msb){
            ans = 0;
            while((y >= 2) && ((y - 1) >> (x + 1) & 1)){
                y--;
                x++;
                ans++;
            }
            ans += y - 1;
            cout << ans << '\n';
            continue;
        }
        ll v = 1ll << msb;
        ll bt;
        for(int i = msb - 1; i >= 0; i--){
            v |= 1ll << i;
            bt = i;
            if(v >= y) break;
        }
        while(x < bt){
            if(~y >> (x + 1) & 1) break;
            if(y < v){
                if((y + 1) >> (x + 1) & 1){
                    y++;
                }
            }
            x++;
            ans++;
        }
        ans += v - 1;
        ans += v - y;
        cout << ans << '\n';
    }
}
0