結果

問題 No.474 色塗り2
ユーザー chaemonchaemon
提出日時 2016-12-24 01:01:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 2,735 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 82,316 KB
実行使用メモリ 34,884 KB
最終ジャッジ日時 2023-08-21 07:44:44
合計ジャッジ時間 1,384 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
34,656 KB
testcase_01 AC 16 ms
34,780 KB
testcase_02 AC 16 ms
34,804 KB
testcase_03 AC 101 ms
34,740 KB
testcase_04 AC 16 ms
34,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

//{{{ gcd and inverse
Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
}
// a x + b y = gcd(a, b)
Int extgcd(Int a, Int b, Int &x, Int &y) {
	Int g = a; x = 1; y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
Int invMod(Int a, Int m) {
	Int x, y;
	if (extgcd(a, m, x, y) == 1) return (x + m) % m;
	else                         return 0; // unsolvable
}
//}}}

Int fact[2000010];
Int b[2000010];

int T,A,B,C;
const int mod = (1<<30);

int comb_mod(int n,int r){
	Int b_count = b[n]-b[r]-b[n-r];
//	assert(b_count>=0);
	if(b_count>=30)return 0;
	Int t = fact[n]*invMod(fact[r],mod)%mod*invMod(fact[n-r],mod)%mod;
	t*=(1ll<<b_count);
	return t%mod;
}

int main(){
	Int u = 1, bct=0;
	for(int i=0;i<=2000000;i++){
		fact[i] = u;
		b[i] = bct;
		
		int t = i+1;
		while(t%2==0)t>>=1,bct++;
		u*=t;
		u%=mod;
	}

	scanf("%d",&T);
	REP(ct,T){
		scanf("%d%d%d",&A,&B,&C);
		if(C%2==0){
			printf("0\n");
			continue;
		}
		Int t = comb_mod(C+B-1,B);
		t*=C;t%=mod;
		t+=A-1;t%=mod;
		int ans;
//		cerr<<t<<" "<<A<<endl;
		while(1){
			if(t%2==0 and A%2==1){
				ans = 0;
				break;
			}
			if(A==0){
				ans = 1;
				break;
			}
			t/=2;A/=2;
		}
		printf("%d\n",ans);
	}
	return 0;
}
0