結果

問題 No.3375 Binary Grid
コンテスト
ユーザー t98slider
提出日時 2025-11-21 23:09:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 195,508 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-11-21 23:10:08
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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), ans = 0, c = x;
        while(y >> (c + 1) & 1) c++;
        if(c == msb){
            cout << y - 1 << '\n';
            continue;
        }
        ll v = 1ll << msb;
        ll bt;
        for(ll i = msb - 1; i >= 0; i--){
            v |= 1ll << i;
            bt = i;
            if(v >= y) break;
        }
        while(y < v){
            if((~y >> (x + 1) & 1) && (~(y + 1) >> (x + 1) & 1)) break;
            if((y + 1) >> (x + 1) & 1){
                y++;
            }
            x++;
            ans++;
        }
        ans += v - 1;
        ans += v - y;
        cout << ans << '\n';
    }
}
0