結果

問題 No.1598 4×4 Grid
ユーザー convexineqconvexineq
提出日時 2021-07-09 23:06:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,521 ms / 4,000 ms
コード長 936 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 202,328 KB
最終ジャッジ日時 2023-09-14 10:39:49
合計ジャッジ時間 17,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,502 ms
202,156 KB
testcase_01 AC 1,509 ms
201,984 KB
testcase_02 AC 1,520 ms
202,008 KB
testcase_03 AC 1,491 ms
201,932 KB
testcase_04 AC 1,513 ms
201,924 KB
testcase_05 AC 1,521 ms
202,120 KB
testcase_06 AC 1,501 ms
202,328 KB
testcase_07 AC 1,509 ms
201,980 KB
testcase_08 AC 1,513 ms
202,052 KB
testcase_09 AC 1,481 ms
202,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

k = int(input())
M = 217
N = 1<<16
d = {1:{0:4},2:{0:8},32:{0:4}}

for i in range(1,16):
    nd = {}
    for mask,dic in d.items():
        for j in range(16):
            if mask>>j&1: continue
            r = 0
            x,y = divmod(j,4)
            if x:
                if mask>>(j-4)&1: r += i
                else: r -= i
            if x < 3:
                if mask>>(j+4)&1: r += i
                else: r -= i
            if y:
                if mask>>(j-1)&1: r += i
                else: r -= i
            if y < 3:
                if mask>>(j+1)&1: r += i
                else: r -= i
            nmask = mask|(1<<j)
            if nmask not in nd: nd[nmask] = {}
            D = nd[nmask]
            for v,c in dic.items():
                v += r
                if v in D:
                    D[v] += c
                else:
                    D[v] = c
    d = nd

dic = d[N-1]
print(0 if k not in dic else dic[k])
0