結果

問題 No.474 色塗り2
ユーザー 👑 kmjpkmjp
提出日時 2016-12-24 01:30:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,728 bytes
コンパイル時間 1,230 ms
コンパイル使用メモリ 145,908 KB
実行使用メモリ 55,020 KB
最終ジャッジ日時 2023-08-21 07:45:36
合計ジャッジ時間 2,004 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
55,012 KB
testcase_01 AC 25 ms
54,920 KB
testcase_02 AC 26 ms
55,020 KB
testcase_03 AC 123 ms
54,916 KB
testcase_04 AC 25 ms
54,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------



int T;
int num2[(1<<22)+100000];
int A,B,C;

ll mo=1<<21;
ll fact[(1<<22)+500000];
ll modpow(ll a, ll n, ll mo) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


ll combi(int N_, int C_) {
	
	int x = num2[N_]-num2[N_-C_]-num2[C_];
	if(x>=21) return 1LL<<21;
	ll ret=1LL<<x;
	ret = ret * fact[N_] % mo;
	ret = ret * modpow(fact[C_],mo/2-1,mo) % mo;
	ret = ret * modpow(fact[N_-C_],mo/2-1,mo) % mo;
	return ret;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}
ll combi2(int N_, int C_) {
	return num2[N_]==num2[C_]+num2[N_-C_];
}
ll hcomb2(int P_,int Q_) { return (P_==0&&Q_==0)?1:combi2(P_+Q_-1,Q_);}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=1;
	FOR(i,(1<<22)+50000) {
		fact[i+1]=fact[i]*(i+1);
		num2[i+1]=num2[i];
		while(fact[i+1]%2==0) num2[i+1]++, fact[i+1]/=2;
		fact[i+1]%=(1<<21);
	}
	
	
	
	cin>>T;
	FOR(i,T) {
		cin>>A>>B>>C;
		if(C%2==0) {
			_P("0\n");
			continue;
		}
		auto k=hcomb(C,B);
		if(k%(1<<21)==0) {
			_P("0\n");
			continue;
		}
		ll a=C*k % (1<<21);
		_P("%lld\n",(hcomb2(a,A)%2));
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0