結果

問題 No.1598 4×4 Grid
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-14 22:51:48
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 761 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 847,412 KB
最終ジャッジ日時 2023-09-17 01:20:00
合計ジャッジ時間 4,349 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

k = int(input())
M = 216*4
dp = [[0]*(2*M+5) for i in range(1<<16)]
dp[0][0] = 1
mi = 0
for i in range(1<<16):
    for j in range(-M,M+1):
        if dp[i][j] == 0:
            continue
        b = bin(i).count("1")
        for c in range(16):
            if i >> c & 1:
                continue
            x,y = divmod(c,4)
            count = 0
            for dx,dy in ((-1,0),(0,-1),(0,1),(1,0)):
                nx = x+dx
                ny = y+dy
                if nx < 0 or ny < 0 or nx > 3 or ny > 3:
                    continue
                if i >> (nx*4+ny) & 1:
                    count += b+1
                else:
                    count -= b+1
            dp[i|1<<c][count+j] += dp[i][j]
            mi = min(mi,count+j)
print(dp[-1][k])
0