結果

問題 No.1598 4×4 Grid
ユーザー ayaoniayaoni
提出日時 2021-07-10 01:30:38
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,206 ms / 4,000 ms
コード長 1,160 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 86,656 KB
実行使用メモリ 194,680 KB
最終ジャッジ日時 2023-09-14 13:00:38
合計ジャッジ時間 10,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 191 ms
88,700 KB
testcase_01 AC 669 ms
114,776 KB
testcase_02 AC 481 ms
115,960 KB
testcase_03 AC 727 ms
138,436 KB
testcase_04 AC 901 ms
153,444 KB
testcase_05 AC 2,031 ms
185,580 KB
testcase_06 AC 2,206 ms
194,680 KB
testcase_07 AC 172 ms
83,832 KB
testcase_08 AC 474 ms
114,784 KB
testcase_09 AC 967 ms
159,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


K = I()

X = [0]*(1<<16)
for i in range(1<<16):
    A = [(i>>j) & 1 for j in range(16)]
    count = 0
    for j in range(4):
        for k in range(3):
            if A[4*j+k] != A[4*j+k+1]:
                count += 1
    for j in range(3):
        for k in range(4):
            if A[4*j+k] != A[4*(j+1)+k]:
                count += 1
    X[i] = count

dp = [[0]*(K+1) for _ in range(1<<16)]
dp[0][0] = 1
for i in range(1,1<<16):
    x = X[i]
    A = []
    for j in range(16):
        if (i>>j) & 1:
            A.append(j)
    for j in range(K+1):
        d = 0
        if j < x:
            continue
        for a in A:
            d += dp[i^(1<<a)][j-x]
        dp[i][j] = d

ans = dp[-1][K]
print(ans)
0