結果

問題 No.506 限られたジャパリまん
ユーザー maspymaspy
提出日時 2020-03-17 22:53:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 77,560 KB
最終ジャッジ日時 2023-09-10 12:56:15
合計ジャッジ時間 3,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,332 KB
testcase_01 AC 74 ms
71,256 KB
testcase_02 AC 79 ms
75,392 KB
testcase_03 AC 74 ms
71,248 KB
testcase_04 AC 80 ms
76,532 KB
testcase_05 AC 77 ms
75,444 KB
testcase_06 AC 74 ms
71,264 KB
testcase_07 AC 80 ms
76,140 KB
testcase_08 AC 131 ms
77,412 KB
testcase_09 AC 118 ms
77,400 KB
testcase_10 AC 86 ms
76,332 KB
testcase_11 AC 125 ms
77,492 KB
testcase_12 AC 117 ms
77,360 KB
testcase_13 AC 72 ms
71,256 KB
testcase_14 AC 81 ms
76,040 KB
testcase_15 AC 74 ms
71,360 KB
testcase_16 AC 123 ms
77,560 KB
testcase_17 AC 83 ms
76,324 KB
testcase_18 AC 84 ms
76,452 KB
testcase_19 AC 93 ms
76,404 KB
testcase_20 AC 94 ms
76,884 KB
testcase_21 AC 84 ms
76,224 KB
testcase_22 AC 98 ms
77,012 KB
testcase_23 AC 89 ms
76,284 KB
testcase_24 AC 85 ms
76,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
MOD = 10**9 + 7

# %%
H, W, K, P = map(int, readline().split())
X = []
Y = []
N = []
for _ in range(K):
    x, y, n = readline().decode().split()
    x = int(x)
    y = int(y)
    X.append(x)
    Y.append(y)
    N.append(n)


# %%
def solve(subset):
    dp = [[0] * (W + 2) for _ in range(H + 2)]
    dp[0][0] = 1
    forbit = [[0] * (W + 1) for _ in range(H + 1)]
    for i in subset:
        x = X[i]
        y = Y[i]
        forbit[x][y] = 1
    for h in range(H + 1):
        for w in range(W + 1):
            if forbit[h][w]:
                dp[h][w] = 0
                continue
            dp[h + 1][w] += dp[h][w]
            dp[h][w + 1] += dp[h][w]
    return dp[H][W]


# %%
best_subset = 0
best_path = 0
for s in itertools.combinations(range(K), K - P):
    x = solve(s)
    if best_path < x:
        best_path = x
        best_subset = s

# %%
if best_path == 0:
    print(0)
else:
    print(best_path % MOD)
    for i in range(K):
        if i in best_subset:
            continue
        print(N[i])
0