結果

問題 No.1403 調和の魔法陣
ユーザー 37zigen37zigen
提出日時 2020-08-13 20:00:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,249 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 11,132 KB
実行使用メモリ 13,068 KB
最終ジャッジ日時 2023-10-12 22:30:46
合計ジャッジ時間 5,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

MOD=998244353
N=9

pows=[]
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
    for min_e in range(min(X+1,N+1)):
        for max_e in range(min_e,min(X+1,N+1)):
            if H==2 and not (min_e==0 and max_e==0):
                continue
            if H==2:
                pat_e=1
            else:
                d=max_e-min_e+1
                pat_e=pows[d][H//2-1]-2*pows[d-1][H//2-1]+pows[max(0,d-2)][H//2-1]
                pat_e%=MOD
            for min_o in range(min(X+1,N+1)):
                for max_o in range(min_o, N+1):
                    pat_o=pows[max_o-min_o+1][H//2]-2*pows[max_o-min_o][H//2]+pows[max(0,max_o-min_o-1)][H//2]
                    pat_o%=MOD
                    for a00 in range(min(X+1,N+1)):
                        upper_o=min(X-a00-max_o,N)
                        lower_o=max(X-a00-N-min_o,0)
                        upper_e=min(a00+min_o,N)
                        lower_e=max(-N+a00+max_o,0)
                        if H>=3:
                            upper_o=min(upper_o,N-a00+min_e)
                            lower_o=max(lower_o,-a00+max_e)
                            upper_e=min(upper_e,N+a00-max_e)
                            lower_e=max(lower_e,a00-min_e)
                        if upper_o-lower_o<0 or (W>2 and upper_e-lower_e<0):
                            continue
                        add=pows[upper_o-lower_o+1][W//2]*pows[upper_e-lower_e+1][W//2-1]%MOD*pat_e%MOD*pat_o%MOD
                        ans=ans+add
                        if ans>=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