結果
| 問題 | 
                            No.2159 Filling 4x4 array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             vwxyz
                         | 
                    
| 提出日時 | 2024-05-03 14:17:18 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,257 bytes | 
| コンパイル時間 | 198 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 253,940 KB | 
| 最終ジャッジ日時 | 2024-11-24 14:55:10 | 
| 合計ジャッジ時間 | 143,355 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 MLE * 4 | 
| other | AC * 9 TLE * 20 MLE * 16 | 
ソースコード
import sys
readline=sys.stdin.readline
from functools import lru_cache
from collections import defaultdict
pow5=[1, 5, 25, 125, 625, 3125, 15625, 78125]
HW=list(map(int,readline().split()))
for i in range(8):
    HW[i]-=4
H,W=HW[:4],HW[4:]
H.sort()
W.sort()
mod=998244353
cnt=[defaultdict(int) for c in range(390625)]
se=set()
for bit in range(1<<16):
    HH=tuple(sum(bit>>h*4+w&1 for w in range(4)) for h in range(4))
    WW=tuple(sum(bit>>h*4+w&1 for h in range(4)) for w in range(4))
    cnt[sum(HH[i]%2*pow5[i] for i in range(4))+sum(WW[i]%2*5**(i+4) for i in range(4))][(HH,WW)]+=1
    se.add((HH,WW))
@lru_cache(maxsize=None)
def solve(H,W):
    for h in H:
        if h<0:
            return 0
    for w in W:
        if w<0:
            return 0
    if all(h==0 for h in H) and all(w==0 for w in W):
        return 1
    retu=0
    for (HH,WW),c in cnt[sum(H[i]%2*pow5[i] for i in range(4))+sum(W[i]%2*5**(i+4) for i in range(4))].items():
        if all(h>=hh and h%2==hh%2 for h,hh in zip(H,HH)) and all(w>=ww and w%2==ww%2 for w,ww in zip(W,WW)):
            retu+=solve(tuple(sorted([h-hh>>1 for h,hh in zip(H,HH)])),tuple(sorted([w-ww>>1 for w,ww in zip(W,WW)])))*c
            retu%=mod
    return retu
ans=solve(tuple(H),tuple(W))
print(ans)
            
            
            
        
            
vwxyz