結果
| 問題 |
No.822 Bitwise AND
|
| コンテスト | |
| ユーザー |
yakamoto
|
| 提出日時 | 2019-08-18 02:43:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 3,150 bytes |
| コンパイル時間 | 1,860 ms |
| コンパイル使用メモリ | 171,924 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 18:18:11 |
| 合計ジャッジ時間 | 2,723 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <iostream>
#include <fstream>
#ifndef SOLUTION_COMMON_H
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PI = pair<int, int>;
template<class T> using V = vector<T>;
using VI = V<int>;
#define _1 first
#define _2 second
#ifdef MY_DEBUG
# define DEBUG(x) x
#else
# define DEBUG(x)
#endif
template<class T>
inline void debug(T &A) {
DEBUG(
for (const auto &a : A) {
cerr << a << " ";
}
cerr << '\n';
)
}
template<class T, class Func>
inline void debug_with_format(T &A, Func f) {
DEBUG(
for (const auto &a : A) {
cerr << f(a) << " ";
}
cerr << '\n';
)
}
template<class T>
inline void debug_dim2(T &A) {
DEBUG(
for (const auto &as : A) {
debug(as);
}
)
}
template<typename ... Args>
inline void debug(const char *format, Args const &... args) {
DEBUG(
fprintf(stderr, format, args ...);
cerr << '\n';
)
}
template<typename ... Args>
string format(const string &fmt, Args ... args) {
size_t len = snprintf(nullptr, 0, fmt.c_str(), args ...);
vector<char> buf(len + 1);
snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
return string(&buf[0], &buf[0] + len);
}
template<class T1, class T2>
string fmtP(pair<T1, T2> a) {
stringstream ss;
ss << "(" << a._1 << "," << a._2 << ")";
return ss.str();
}
#define SOLUTION_COMMON_H
#endif //SOLUTION_COMMON_H
int msb(int i) {
i |= (i >> 1);
i |= (i >> 2);
i |= (i >> 4);
i |= (i >> 8);
i |= (i >> 16);
return i - (((unsigned int)i) >> 1);
}
int log2(int x) {
int i = 0;
while(x >>= 1) i++;
return i;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
VI divisors(int x) {
VI D, back;
int rt = (int)sqrt(x);
for (int d = 1; d <= rt; ++d) {
if (x % d == 0) {
D.push_back(d);
if (d * d != x) back.push_back(x / d);
}
}
D.insert(D.end(), back.rbegin(), back.rend());
return D;
}
ll pow_mod(ll x, int k, ll m) {
if (k == 0) return 0;
else if (k == 1) return x;
else {
ll a = pow_mod(x * x % m, k / 2, m);
if (k % 2 == 1) a = a * x % m;
return a;
}
}
//inline void add(ll &a, ll b) {
// a += b;
// if (a >= MOD) a -= MOD;
//}
//
//inline void sub(ll &a, ll b) {
// a += MOD - b;
// if (a >= MOD) a -= MOD;
//}
//
//inline void mul(ll &a, ll b) {
// a = a * b % MOD;
//}
const int MOD = 1000000007;
class A {
public:
void solve(std::istream& in, std::ostream& out) {
int N, K;
in >> N >> K;
int nextBit = max(msb(N) << 1, 1);
int x0 = nextBit - 1;
int y0 = nextBit + N;
if (y0 - x0 <= K) {
out << "INF";
return;
}
debug("nextBit:%d", nextBit);
ll ans = 0ll;
for (int x = N; x < nextBit; ++x) {
if ((x & N) != N) continue;
debug("x:%d", x);
for (int y = x; y <= x + K; ++y) {
if ((x & y) == N) ++ans;
}
}
out << ans;
}
};
int main() {
A solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
yakamoto