結果

問題 No.822 Bitwise AND
ユーザー chocopuuchocopuu
提出日時 2019-04-26 22:56:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,242 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 169,988 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 16:23:45
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
/*
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
*/
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
const long long MOD = 1000000007, INF = 1e18;
string get_str(string s)
{
	s += ',';
	string ret = "";
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == ',')
			ret += "=%ld, ";
		else
			ret += s[i];
	}
	return ret;
}
#define dump(...)                                       \
	printf(get_str(#__VA_ARGS__).c_str(), __VA_ARGS__); \
	cout << endl
//******************************************************************************

template <typename T>
vector<T>
make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
	for (auto &e : t)
		fill_v(e, v);
}

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

signed main()
{
	int N, K, ma = -1;
	cin >> N >> K;
	if (K == 0)
	{
		cout << 1 << endl;
		return 0;
	}
	if ((K % 2 == 0 || K == 1)&&(N&K)==0)
	{
		cout << "INF" << endl;
		return 0;
	}
	int n = N;
	vector<int> cnt(100, 0), v;
	v.push_back(0);
	int tmp = 0;
	for (int i = 0; i < 20; i++)
	{
		if (N & 1)
		{
			cnt[i]++;
		}
		else
		{
			v.push_back(1ll << i);
		}
		N /= 2;
	}
	auto dp = make_v<int>(101010);
	fill_v(dp, 0);
	dp[0] = 1;
	for (int i = 0; i < v.size(); i++)
	{
		rrep(j, 0, 100301)
		{
			if (j + v[i] < 100301)
				dp[j + v[i]] |= dp[j];
		}
	}
	N = n;
	int ans = 0;
	for (int i = 0; i < N + K + 1; i++)
	{
		if (!dp[i])
			continue;
		for (int j = max(0ll, i - K); j < i + 1; j++)
		{
			if (!dp[j])
				continue;
			if ((i & j) == 0)
				ans++;
		}
	}
	cout << ans << endl;
}
0