結果

問題 No.2393 Bit Grid Connected Component
ユーザー Astral__Astral__
提出日時 2023-07-28 21:57:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 6,527 bytes
コンパイル時間 3,452 ms
コンパイル使用メモリ 207,940 KB
実行使用メモリ 18,116 KB
最終ジャッジ日時 2024-04-16 05:52:09
合計ジャッジ時間 7,546 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
18,116 KB
testcase_01 AC 6 ms
10,988 KB
testcase_02 AC 6 ms
11,028 KB
testcase_03 AC 6 ms
11,084 KB
testcase_04 AC 6 ms
11,072 KB
testcase_05 AC 6 ms
11,020 KB
testcase_06 AC 6 ms
10,932 KB
testcase_07 AC 6 ms
11,028 KB
testcase_08 AC 6 ms
11,012 KB
testcase_09 AC 22 ms
10,984 KB
testcase_10 AC 415 ms
11,024 KB
testcase_11 AC 219 ms
11,160 KB
testcase_12 AC 606 ms
10,988 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define PPque priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>>
#define Pque  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
#define pque priority_queue<int, vector<int>, greater<int>>
#define umap unordered_map
#define uset unordered_set
#define rep(i, s, f) for(int i = s; i <= f; i++)
#define per(i, s, f) for(int i = s; i >= f; i--)
#define all0(x) (x).begin() ,(x).end()
#define all(x) (x).begin() + 1, (x).end()
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvs vector<vector<string>>
#define vvc vector<vector<char>>
#define vvp vector<vector<pair<ll, ll>>>
#define vp vector<pair<ll, ll>>
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define P pair<ll, ll>
#define ENDL '\n'
#define ull unsigned long long
typedef  long long ll;
using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//いだいなる あるごりずむ たち 。

template <typename T> //配列の最後の要素を取得
T getlast(vector<T> &A) {
  return A.at(A.size() - 1);
}
template <typename T>
T or_less(vector<T> &A, T x) { //x以下で最大要素の添字 前提: sort済み 存在しない: -1
  return distance(A.begin(), upper_bound(A.begin(), A.end(), x)-1);
}
template <typename T>
T under(vector<T> &A, T x) { //x未満の最大要素の添字 前提: sort済み 存在しない: -1
  return distance(A.begin(), lower_bound(A.begin(), A.end(), x)-1);
}
template <typename T>
T or_more(vector<T> &A, T x) { //x以上で最小要素の添字  前提: sort済み 存在しない: N .   //distanceのA.beginは添字を出すために常にA.begin() NG: A.begin() + 1
  return distance(A.begin(), lower_bound(A.begin(), A.end(), x));
}
template <typename T>
T over(vector<T> &A, T x) { //xより大きい最小要素の添字前提: sort済み 存在しない: N
  return distance(A.begin(), upper_bound(A.begin(), A.end(), x));
}
template <typename T>
T getidx(vector<T> &A, T x) {//or_moreとover必須、存在しないならば-1、重複要素については一番前のやつ
    int smaller = or_more<T>(A, x);
    int bigger = over<T>(A, x);
    if (smaller != bigger) {
        return smaller;
    }
    else {
        return -1;
    }
}
template <typename T>
T MIN(T &a, T &b) {
  if (a < 0 && b < 0) {
    return -1;
  }
  else if (a < 0) {
    return b;
  }
  else if (b < 0) {
    return a;
  }
  else {
    return min(a, b);
  }
}
template <typename T>
T MAX(T &a, T &b) {
  if (a >= 1e9 && b > 1e9) {
    return -1;
  }
  else if (a >= 1e9) {
    return b;
  }
  else if (b >= 1e9) {
    return a;
  }
  else {
    return max(a, b);
  }
}
//////////////////////////////////////////////////////////////////////
//数学系
///////////////////////////////////////////////////////////////////////
ll POWER(ll a, ll b, ll mod) {
    a %= mod;
    vector<ll> pow (61);
    pow.at(0) = a;
    bitset<60> bina(b);
    ll answer = 1;
    for (int i = 1; i <= 60; i++) {
      pow.at(i) = pow.at(i-1) * pow.at(i-1) % mod;
        if (bina.test(i-1)) {
            answer = (answer*pow.at(i-1)) % mod;
        }
    }
    return answer;
}
ll Div(ll a, ll b, ll mod) {
    return a * POWER(b, mod-2, mod) % mod;
}

ll round(ll x, ll i) {
    return ll(x + 5 * pow(10, i-1))/ll(pow(10, i)) * ll(pow(10, i));
}
template <typename T> //約分
void normalize(T &mol, T &deno) {
    T mol_temp = abs(mol);
    T deno_temp = abs(deno);
    T GCD = gcd(mol_temp, deno_temp);
    mol /= GCD;
    deno /= GCD;
}
vvl mat_mul(vvl &a, vvl &b, ll mod) {//0-indexed && 正方行列
  ll n = a.size();
  vvl res(n , vl(n, 0));
 
  rep(i, 0, n-1) {
    rep(j, 0, n-1) {
      rep(k, 0, n-1) {
        res.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j);
        res.at(i).at(j) %= mod;
      }
    }
  }
  return res;
}
vvl mat_pow(vvl &a, ll b, ll mod) {//0-indexed && 正方行列
  bitset<60> bina(b);
  vvl power = a;
  int N = a.size();
  vvl res(N, vl(N, 0));
  rep(i, 0, N-1) {
    res.at(i).at(i) = 1;
  }
  rep(i, 1, 60) {
    if (bina.test(i-1)) {
      res = mat_mul(res, power, mod);
    }
    power = mat_mul(power, power, mod);
  }
  return res;
}

vvl comb(ll n, ll mod) {//計算にO(N^2) 読み取りにO(1)
  vvl v(n+1, vl(n+1, 0));
  rep(i, 0, v.size() - 1) {
    v.at(i).at(0) = 1;
    v.at(i).at(i) = 1;
  }

  rep(i, 1, v.size()-1) {
    rep(j, 1, i) {
      v.at(i).at(j) = v.at(i-1).at(j-1) + v.at(i-1).at(j);
      v.at(i).at(j) %= mod;
    }
  }
  return v;
}

ll nCk(int n, int k, ll mod) {//毎回O(max(分子、 分母))
  ll ue = 1;
  ll sita = 1;
  for (int i = 1; i <= k; i++) {
      sita *= i;
      sita %= mod;
  }
  for (int i = 1; i <= k; i++) {
    ue *= (n-i+1);
    ue %= mod;
  }

  return Div(ue, sita, mod);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//グローバル変数を置くところ(情報工学意識高め)
ll int_max = 1e9;
ll ll_max = 1e18;
const double pi = 3.141592653589793;
//cout << fixed << setprecision(10);
#pragma GCC optimize ("-O3")
//ll mod = 1000000007;
//ll mod = 998244353;
#pragma GCC optimize("unroll-loops")
  vl c(500001);
    vl cnt(500001, 0);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
  ll y, x;
  cin >> y >> x;
  x++;
  ll teisu = (1LL << 61) - 2;
  while(true) {

    if(y <= teisu && ((y+1) >> (x-1)) & 1) {
      y++;
    }
    else {
      break;
    }
  }
  vl can;
  can.push_back(x);
  rep(i, x+1, 60) {
    
    if(y >> (i-1) & 1) {
      can.push_back(i);
    }
    else {
      break;
    }
  }
  per(i, x-1, 1) {
    ll l = 60 - i  + 1;
    if(y >> (i-1) & 1) {
      can.push_back(i);
    }
    else {
      break;
    }
  }


  ll ans = 0;
  vl p2(61, 1);
  rep(i, 1, 60) {
    p2.at(i) = p2.at(i-1) * 2;
  }


  for (ll i : can) {
    ans += p2.at(i-1);
  }
  cout << ans << endl;



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

  ll T;
  cin >> T;
  rep(i, 1, T) {
    solve();
  }

  



 

}

// modは取りましたか...?(´・ω・`)
0