結果
問題 |
No.2983 Christmas Color Grid (Advent Calender ver.)
|
ユーザー |
![]() |
提出日時 | 2024-12-09 18:39:20 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,671 bytes |
コンパイル時間 | 833 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 161,664 KB |
最終ジャッジ日時 | 2024-12-09 18:41:19 |
合計ジャッジ時間 | 118,575 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 TLE * 1 MLE * 1 |
other | AC * 35 TLE * 20 MLE * 9 |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 # md = 998244353 def cal(a): def dfs(ij): def push(ij): if a[ij]==0:return a[ij]=0 st.append(ij) cnt=0 st=[ij] a[ij]=0 while st: ij=st.pop() cnt+=1 i,j=divmod(ij,w) if i+1<h:push(ij+w) if j+1<w:push(ij+1) if i:push(ij-w) if j:push(ij-1) return val[cnt] res=0 for i in range(h): for j in range(w): ij=i*w+j if a[ij]==0:continue res+=dfs(ij) res%=md return res h,w,k,md=LI() n=h*w val=[pow(i,k,md) for i in range(n+1)] st=[[]] s=0 while st: a=st.pop() if len(a)==n: s+=cal(a) s%=md else: st.append(a+[0]) st.append(a+[1]) coe=0 for i in range(n): coe+=pow(i+1,md-2,md) coe%=md ans=s*coe%md*pow(2,n*(md-2),md)%md print(ans)