結果

問題 No.474 色塗り2
ユーザー antaanta
提出日時 2016-12-24 00:28:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 167,016 KB
実行使用メモリ 10,904 KB
最終ジャッジ日時 2023-08-21 07:43:00
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,904 KB
testcase_01 AC 10 ms
10,720 KB
testcase_02 AC 9 ms
10,744 KB
testcase_03 AC 57 ms
10,772 KB
testcase_04 AC 10 ms
10,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

unsigned inv2adic(unsigned x) {
	unsigned i = x, p;
	do {
		p = i * x;
		i *= 2U - p;
	} while (p != 1);
	return i;
}

inline int popcount(unsigned x) {
#ifdef __GNUC__
	return __builtin_popcount(x);
#else
	return _mm_popcnt_u32(x);
#endif
}

int main() {
	int T;
	scanf("%d", &T);
	const int N = 2000000;
	vector<unsigned> fact(N + 1);
	fact[0] = 1;
	rep(i, N) {
		unsigned x = i + 1;
		while ((x & 1) == 0) x >>= 1;
		fact[i + 1] = fact[i] * x;
	}
	for (int ii = 0; ii < T; ++ii) {
		int A; int B; int C;
		scanf("%d%d%d", &A, &B, &C);
		//C(C(c+b-1,b) * c + a - 1, a) * c
		int n = C + B - 1, r = B;
		int val = 0;
		val -= popcount(n);
		val += popcount(r);
		val += popcount(n - r);
		unsigned x = fact[n] * inv2adic(fact[r] * fact[n - r]);
		x <<= min(val, 30);
		x *= C;
		x += A - 1;
		int ans = (A & ~x) == 0 && C % 2 == 1 ? 1 : 0;
		printf("%d\n", ans);
	}
	return 0;
}
0