結果

問題 No.3375 Binary Grid
コンテスト
ユーザー テナガザル
提出日時 2025-11-21 23:19:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 104,428 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-21 23:19:40
合計ジャッジ時間 3,458 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

void solve()
{
  long long r, c;
  cin >> r >> c;
  --c;
  vector<int> b(60);
  for (int i = 0; i < 60; ++i) b[i] = (r >> i) & 1;
  long long ans = 0, tb = 0, tmp = 0;
  for (int i = 59; i >= 0; --i)
  {
    if (b[i])
    {
      tb = i;
      int j = tb;
      while (j >= c)
      {
        tmp += (1LL << j);
        if (tmp > r) break;
        --j;
      }
      if (r >= tmp) ans = r - 1;
      else
      {
        while (r < tmp)
        {
          if ((r + 1) & (1LL << (c + 1)))
          {
            ++r;
            ++c;
          }
          else if (r & (1LL << (c + 1)))
          {
            ++c;
          }
          else break;
          ++ans;
        }
        ans += max(tmp - r, j - c) + tmp - 1;
      }
      break;
    }
  }
  cout << ans << endl;
}

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