結果

問題 No.506 限られたジャパリまん
ユーザー rlangevinrlangevin
提出日時 2023-09-27 12:26:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,192 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 77,756 KB
最終ジャッジ日時 2023-09-27 12:26:28
合計ジャッジ時間 4,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,992 KB
testcase_01 AC 74 ms
71,456 KB
testcase_02 AC 87 ms
75,736 KB
testcase_03 AC 72 ms
71,480 KB
testcase_04 AC 101 ms
77,340 KB
testcase_05 AC 87 ms
76,696 KB
testcase_06 AC 73 ms
71,104 KB
testcase_07 AC 85 ms
76,272 KB
testcase_08 AC 142 ms
77,596 KB
testcase_09 AC 139 ms
77,512 KB
testcase_10 AC 96 ms
76,868 KB
testcase_11 AC 181 ms
77,668 KB
testcase_12 AC 129 ms
77,496 KB
testcase_13 AC 73 ms
71,168 KB
testcase_14 AC 83 ms
76,200 KB
testcase_15 AC 74 ms
71,320 KB
testcase_16 AC 144 ms
77,324 KB
testcase_17 AC 95 ms
76,720 KB
testcase_18 AC 100 ms
77,320 KB
testcase_19 AC 113 ms
77,284 KB
testcase_20 AC 119 ms
77,628 KB
testcase_21 AC 114 ms
77,448 KB
testcase_22 AC 125 ms
77,724 KB
testcase_23 AC 146 ms
77,756 KB
testcase_24 AC 99 ms
77,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(n):
    cnt = 0
    while n:
        cnt += n & 1
        n >>= 1
    return cnt


H, W, K, P = map(int, input().split())
mod = 10 ** 9 + 7
L = []
G = [[1] * (W + 1) for i in range(H + 1)]
for i in range(K):
    lst = input().split()
    lst[0] = int(lst[0])
    lst[1] = int(lst[1])
    G[lst[0]][lst[1]] = 0
    lst.append(i)
    L.append(lst)

K2 = 1 << K
maxv = 0
name = None

def calc():
    dp = [[0] * (W + 1) for i in range(H + 1)]
    dp[0][0] = 1
    for i in range(H + 1):
        for j in range(W + 1):
            if i == j == 0 or G[i][j] == 0:
                continue
            if i:
                dp[i][j] += dp[i - 1][j]
            if j:
                dp[i][j] += dp[i][j - 1]
    return dp[H][W]



for s in range(K2):
    if popcount(s) != P:
        continue
    for x, y, _, ind in L:
        if (s >> ind) & 1:
            G[x][y] = 1

    temp = calc()
    if temp > maxv:
        maxv = temp
        name = []
        for x, y, n, ind in L:
            if (s >> ind) & 1:
                name.append(n)

    for x, y, _, ind in L:
        if (s >> ind) & 1:
            G[x][y] = 0
    
print(maxv%mod)
if name:
    for n in name:
        print(n)
0