結果

問題 No.1598 4×4 Grid
ユーザー convexineqconvexineq
提出日時 2021-07-09 23:06:13
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 1,423 ms / 4,000 ms
コード長 936 bytes
コンパイル時間 505 ms
使用メモリ 207,224 KB
最終ジャッジ日時 2023-02-02 01:06:25
合計ジャッジ時間 16,886 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1,408 ms
207,056 KB
testcase_01 AC 1,402 ms
206,940 KB
testcase_02 AC 1,405 ms
207,048 KB
testcase_03 AC 1,419 ms
207,164 KB
testcase_04 AC 1,423 ms
206,992 KB
testcase_05 AC 1,408 ms
207,052 KB
testcase_06 AC 1,421 ms
206,948 KB
testcase_07 AC 1,408 ms
206,912 KB
testcase_08 AC 1,423 ms
207,224 KB
testcase_09 AC 1,411 ms
207,088 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