結果

問題 No.506 限られたジャパリまん
ユーザー nanaenanae
提出日時 2017-04-21 23:09:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 8,480 KB
最終ジャッジ日時 2023-09-10 12:52:04
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,236 KB
testcase_01 AC 17 ms
8,280 KB
testcase_02 AC 16 ms
8,332 KB
testcase_03 AC 16 ms
8,356 KB
testcase_04 AC 19 ms
8,388 KB
testcase_05 AC 16 ms
8,444 KB
testcase_06 AC 16 ms
8,360 KB
testcase_07 AC 18 ms
8,480 KB
testcase_08 AC 276 ms
8,436 KB
testcase_09 AC 135 ms
8,400 KB
testcase_10 AC 21 ms
8,460 KB
testcase_11 AC 237 ms
8,316 KB
testcase_12 AC 142 ms
8,268 KB
testcase_13 AC 16 ms
8,364 KB
testcase_14 AC 18 ms
8,392 KB
testcase_15 AC 16 ms
8,292 KB
testcase_16 AC 255 ms
8,248 KB
testcase_17 AC 22 ms
8,364 KB
testcase_18 AC 22 ms
8,384 KB
testcase_19 AC 37 ms
8,380 KB
testcase_20 AC 68 ms
8,348 KB
testcase_21 AC 29 ms
8,336 KB
testcase_22 AC 78 ms
8,288 KB
testcase_23 AC 56 ms
8,328 KB
testcase_24 AC 21 ms
8,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import combinations

mod = 10**9 + 7

def solve():
    h, w, k, p = map(int, input().split())
    fr = []

    for i in range(k):
        x, y, name = input().split()
        x = int(x)
        y = int(y)
        fr.append((x, y, name))

    max_keiro = -1
    omit = []

    for cmb in combinations(range(k), k - p):
        dp = [[0]*(h + 1) for i in range(w + 1)]
        taboo = [[False]*(h + 1) for i in range(w + 1)]

        for i in cmb:
            x, y, name = fr[i]
            taboo[y][x] = True

        for x in range(h + 1):
            if taboo[0][x]:
                break
            dp[0][x] = 1

        for y in range(w + 1):
            if taboo[y][0]:
                break
            dp[y][0] = 1

        for y in range(1, w + 1):
            for x in range(1, h + 1):
                if taboo[y][x]:
                    continue

                dp[y][x] = dp[y - 1][x] + dp[y][x - 1]

        if dp[w][h] > max_keiro:
            max_keiro = dp[w][h]
            omit = set(cmb)

    print(max_keiro % mod)

    if max_keiro == 0:
        return

    for i in range(k):
        if i not in omit:
            print(fr[i][2])

if __name__ == '__main__':
    solve()
0