結果
| 問題 |
No.1403 調和の魔法陣
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-21 04:59:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,657 bytes |
| コンパイル時間 | 427 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 87,940 KB |
| 最終ジャッジ日時 | 2024-09-14 20:45:53 |
| 合計ジャッジ時間 | 25,113 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | RE * 19 |
ソースコード
MOD=998244353
N=9
pows=[]
inv=[1,1]
for i in range(2,1000):
inv.append(MOD-(MOD//i)*inv[MOD%i]%MOD)
xmax=81
dp=[[[0]*(xmax+1) for i in range(101)] for _ in range(101)]
for X in range(0,xmax+1):
for min_e in range(min(X + 1, N + 1)):
for max_e in range(min_e, min(X + 1, N + 1)):
for min_o in range(min(X + 1, N + 1)):
for max_o in range(min_o, N + 1):
for a00 in range(min(X + 1, N + 1)):
upper_o = min([N - a00 + min_e, X - a00 - max_o, N])
lower_o = max([-a00 + max_e, X - a00 - N - min_o, 0])
upper_e = min([N + a00 - max_e, a00 + min_o, N])
lower_e = max([a00 - min_e, -N + a00 + max_o, 0])
if upper_o - lower_o < 0 or upper_e - lower_e < 0:
continue
for pair0 in [[inv[max_e-min_e+1],max_e-min_e+1],[-2*inv[max_e-min_e],max_e-min_e],[inv[max(0,max_e-min_e-1)],max_e-min_e-1]]:
for pair1 in [[1,max_o-min_o+1],[-2,max_o-min_o],[1,max(0,max_o-min_o-1)]]:
dp[(upper_o-lower_o+1)*(upper_e-lower_e+1)][pair0[1]*pair1[1]][X]+=inv[upper_e-lower_e+1]*pair0[0]%MOD*pair1[0]%MOD
dp[(upper_o-lower_o+1)*(upper_e-lower_e+1)][pair0[1]*pair1[1]][X]%=MOD
for n in range(11):
a=[1]
for i in range(601):
a.append(a[-1]*n%MOD)
pows.append(a)
def solvesub(W,H,X):
ans=0
if H==2:
cnt=[0]*(2*N+1)
for i in range(0,N+1):
for j in range(0,N+1):
cnt[i+j]+=1
for a in range(2*N+1):
b=X-a
if b<0 or b>2*N:
continue
ans+=pow(cnt[a],W//2)*pow(cnt[b],(W+1)//2)
ans%=MOD
print(ans)
return
elif W==2:
return solvesub(H,W,X)
for a in range(101):
for b in range(101):
ans+=dp[a][b][X]*pows[a][W//2]%MOD*pows[b,H//2]%MOD
ans%=MOD
print(ans)
def solve(W,H,X):
if W%3>H%3:
W,H=H,W
if (W%3==0 and H%3==0) or (W%3==0 and H%3==1) or (W%3==1 and H%3==1):
print(int(X<=N))
elif W%3==0 and H%3==2:
d=min(N,X)-max(0,X-N)+1
d=max(0,d)
print(pow(d,W//3,MOD))
elif W%3==1 and H%3==2:
d=min(N,X)-max(0,X-N)+1
d=max(0,d)
print(pow(d,(W+2)//3,MOD))
elif W%3==2 and H%3==2:
solvesub((W+1)//3*2,(H+1)//3*2,X)
else:
raise Exception
def run():
T=int(input())
for t in range(T):
W,H,X=map(int,input().split())
solve(W,H,X)
run()