結果

問題 No.822 Bitwise AND
ユーザー hoyamaghoyamag
提出日時 2019-04-26 23:17:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,201 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 169,132 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 01:12:04
合計ジャッジ時間 5,170 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 141 ms
4,384 KB
testcase_02 AC 1,257 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,388 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 419 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL N, K;
LL dfs(LL x, LL y, VEC<LL> bar) {
  // DUMP(x, y, bar);
  if (bar.size() == 0) {
    if (y - x <= K && x <= y) {
      return 1;
    }
    return 0;
  }
  if (y - x > 4 * K) return 0;
  LL cnt = 0;
  LL t = bar.back();
  bar.pop_back();
  cnt += dfs(x, y, bar);
  cnt += dfs(x + (1 << t), y, bar);
  cnt += dfs(x, y + (1 << t), bar);
  return cnt;
}

const LL MAX_N = 1e5;
int main() {
  cin >> N >> K;
  LL Y = 1;
  LL X = 0;
  while (Y <= N) {
    X += Y;
    Y <<= 1;
  }
  Y += N;
  // DUMP(X,Y,K);
  if (Y - X <= K) {
    cout << "INF" << endl;
    return 0;
  }

  LL bit = 0;
  VEC<LL> bar;
  while ((1 << bit) <= MAX_N) {
    if (((1 << bit) & N) == 0) {
      bar.push_back(bit);
    }
    ++bit;
  }
  // DUMP(bar);
  LL ans = dfs(N, N, bar);
  cout << ans << endl;

  return 0;
}
0