結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー tailstails
提出日時 2022-12-09 11:40:45
言語 cLay
(20241019-1)
結果
AC  
実行時間 346 ms / 1,000 ms
コード長 749 bytes
コンパイル時間 2,659 ms
コンパイル使用メモリ 173,592 KB
実行使用メモリ 31,488 KB
最終ジャッジ日時 2024-10-14 18:36:03
合計ジャッジ時間 20,598 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

char pc[1<<19],pa[1<<19];
unsigned bs[19];

pair<ll,ll> f(int s,unsigned b :Memoize[19,524288]){
	pair<ll,ll> z{};
	int d=pc[b];
	if(d==1){
		z.first=b&bs[s]?1:0;
	}else{
		int e=d>>1;
		int k=0;
		for(unsigned g=b;g=g-1&b;){
			++k;
			if(pc[g]==e){
				auto r1=f(s,b^g);
				auto r2=f(s+(d-e),g);
				if(pa[k]){
					z.first+=r1.first*r2.second+r1.second*r2.first;
					z.second+=r1.first*r2.first+r1.second*r2.second;
				}else{
					z.first+=r1.first*r2.first+r1.second*r2.second;
					z.second+=r1.first*r2.second+r1.second*r2.first;
				}
			}
		}
	}
	return z;
}

{
	rep(i,1<<19){
		pc[i]=__builtin_popcount(i);
		pa[i]=pa[i>>1]^pc[i]&~i&1;
	}
	rep(i,19){
		ll@l;
		rep(l){
			ll@a;
			bs[i]|=1<<a-1;
		}
	}
	auto r=f(0,(1<<19)-1);
	wt(r);
}
0