結果

問題 No.1403 調和の魔法陣
ユーザー 37zigen37zigen
提出日時 2020-08-21 05:20:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,659 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 90,896 KB
最終ジャッジ日時 2023-10-12 22:34:42
合計ジャッジ時間 14,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 963 ms
85,596 KB
testcase_01 AC 955 ms
85,616 KB
testcase_02 AC 957 ms
85,572 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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(101):
    a=[1]
    for i in range(301):
        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()
0