結果

問題 No.2983 Christmas Color Grid (Advent Calender ver.)
ユーザー 👑 p-adic
提出日時 2024-11-21 11:44:12
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 757 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 82,272 KB
実行使用メモリ 301,980 KB
最終ジャッジ日時 2024-11-21 11:44:45
合計ジャッジ時間 28,721 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1 MLE * 1
other AC * 56 TLE * 1 MLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

R=range
H,W,K,M=map(int,input().split())
HW=H*W
p=1<<HW
found=set()
count=[0]*(HW+1)
dfs=[]
for h in R(H):
	for w in R(W):
		i=h*W+w
		s=1<<i
		found.add(s)
		bs=0
		for dx,dy in zip([-1,0,1,0],[0,-1,0,1]):
			if 0<=h+dx<H and 0<=w+dy<W:
				j=i+dx*W+dy
				bs|=(1<<j)
		dfs+=[[s,bs]]
while dfs:
	s,bs=dfs.pop()
	c=sum((s>>d)&1for d in R(HW))
	count[c]+=1<<(HW-c-sum((bs>>d)&1for d in R(HW)))
	for i in R(HW):
		if(bs>>i)&1<1:continue
		h,w=i//W,i%W
		t=s|(1<<i)
		if t in found:continue;
		found.add(t)
		bt=bs^(1<<i)
		for dx,dy in zip([-1,0,1,0],[0,-1,0,1]):
			if 0<=h+dx<H and 0<=w+dy<W:
				j=i+dx*W+dy
				if(s>>j)&1<1:bt|=(1<<j)
		dfs+=[[t,bt]]
print(sum(pow(c,K,M)*count[c]for c in R(1,HW+1))*sum(pow(HW-n+1,-1,M)for n in R(1,HW+1))*pow(2,-HW,M)%M)
0