結果

問題 No.822 Bitwise AND
ユーザー kenken714kenken714
提出日時 2019-04-26 21:57:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,384 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 86,444 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 22:29:39
合計ジャッジ時間 1,262 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll s[30];
vector<ll> list, l2;
int main() {
	ll n, m, now = 0, ans = 0;
	cin >> n >> m;
	ll nn = n;//debug
	if (n == 0) {
		if (m % 2 == 1) {
			cout << "INF" << endl;
			return 0;
		}
	}
	while (n > 0) {
		if (n % 2 == 1)s[now] = 1;
		now++;
		n /= 2;
	}
	REP(i, 10) {
		if (s[i] == 0)list.push_back(pow(2, i));
		if (s[i] == 0)l2.push_back(pow(2, i));
	}
	
	REP(i, 1ll << (ll)list.size()) {
		REP(k, 1ll << (ll)l2.size()) {
			if (i < k)break;
			bool ok = true;
			REP(j, l2.size()) {
				if (i & (1 << j) and k & (1 << j))ok = false;
			}
			if (!ok)break;
			ll s1 = 0, s2 = 0;
			REP(j, list.size()) {
				if (i & (1 << j))s1 += list[j];
			}
			REP(j, l2.size()) {
				if (k & (1 << j))s2 += l2[j];
			}
			if (m >= abs(s1 - s2))ans++;

		}
	}
	cout << ans << endl;
}
0