結果

問題 No.506 限られたジャパリまん
ユーザー sue_charosue_charo
提出日時 2017-06-01 23:07:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,935 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 10,340 KB
最終ジャッジ日時 2023-09-10 12:54:23
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,128 KB
testcase_01 AC 32 ms
10,276 KB
testcase_02 AC 32 ms
10,092 KB
testcase_03 AC 32 ms
10,188 KB
testcase_04 AC 34 ms
10,340 KB
testcase_05 AC 32 ms
10,248 KB
testcase_06 AC 31 ms
10,276 KB
testcase_07 AC 34 ms
10,220 KB
testcase_08 AC 277 ms
10,208 KB
testcase_09 AC 142 ms
10,200 KB
testcase_10 AC 35 ms
10,088 KB
testcase_11 AC 253 ms
10,080 KB
testcase_12 AC 166 ms
10,076 KB
testcase_13 AC 32 ms
10,168 KB
testcase_14 AC 33 ms
10,220 KB
testcase_15 AC 31 ms
10,200 KB
testcase_16 AC 227 ms
10,052 KB
testcase_17 AC 38 ms
10,152 KB
testcase_18 AC 39 ms
10,156 KB
testcase_19 AC 54 ms
10,108 KB
testcase_20 AC 85 ms
10,176 KB
testcase_21 AC 45 ms
10,220 KB
testcase_22 AC 95 ms
10,208 KB
testcase_23 AC 72 ms
10,336 KB
testcase_24 AC 35 ms
10,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    H, W, K, P = ILI()
    ani = []
    for __ in range(K):
        x, y, name = input().split()
        ani.append((int(x), int(y), str(name)))
    return (H, W, K, P, ani)


def solve(H, W, K, P, ani):
    ans_num = -1
    ans_ind = 0
    dif_k = K - P

    for ani_ind in itertools.combinations(range(K), dif_k):
        board = [[0] * (W + 1) for __ in range(H + 1)]
        board_bool = [[False] * (W + 1) for __ in range(H + 1)]

        for ind in ani_ind:
            x, y, name = ani[ind]
            board_bool[x][y] = True

        for h in range(H + 1):
            if board_bool[h][0]:
                break
            board[h][0] = 1

        for w in range(W + 1):
            if board_bool[0][w]:
                break
            board[0][w] = 1

        for w in range(1, W + 1):
            for h in range(1, H + 1):
                if board_bool[h][w]:
                    continue
                else:
                    board[h][w] = board[h - 1][w] + board[h][w - 1]

        if ans_num < board[H][W]:
            ans_num = board[H][W]
            ans_ind = ani_ind

    if ans_num == 0:
        return 0
    else:
        ans = []
        ans.append(ans_num % MOD)
        for ind in range(K):
            if ind in ans_ind:
                continue
            x, y, name = ani[ind]
            ans.append(name)

    return ans


def main():
    params = read()
    ans = solve(*params)
    if isinstance(ans, int):
        print(ans)
    else:
        for a in ans:
            print(a)


if __name__ == "__main__":
    main()
0