結果

問題 No.506 限られたジャパリまん
ユーザー sue_charosue_charo
提出日時 2017-06-01 22:54:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,953 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 10,308 KB
最終ジャッジ日時 2023-09-10 12:54:20
合計ジャッジ時間 3,094 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,116 KB
testcase_01 AC 31 ms
10,124 KB
testcase_02 AC 32 ms
10,076 KB
testcase_03 AC 32 ms
10,120 KB
testcase_04 AC 34 ms
10,132 KB
testcase_05 AC 32 ms
10,268 KB
testcase_06 AC 32 ms
10,112 KB
testcase_07 AC 34 ms
10,232 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 251 ms
10,136 KB
testcase_12 AC 161 ms
10,236 KB
testcase_13 AC 32 ms
10,148 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 38 ms
10,152 KB
testcase_18 AC 38 ms
10,264 KB
testcase_19 AC 53 ms
10,184 KB
testcase_20 AC 84 ms
10,120 KB
testcase_21 AC 45 ms
10,156 KB
testcase_22 AC 96 ms
10,232 KB
testcase_23 AC 73 ms
10,164 KB
testcase_24 AC 37 ms
10,156 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 nCk(n, k):
    return math.factorial(n) // (math.factorial(n - k) * math.factorial(k))


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 = 0
    ans_ind = 0
    dif_k = K - P

    for ani_ind in itertools.combinations(range(K), dif_k):
        board = [[-1] * (W + 1) for __ in range(H + 1)]
        for ind in ani_ind:
            x, y, name = ani[ind]
            board[x][y] = 0
        for h in range(H + 1):
            if board[h][0] == 0:
                break
            board[h][0] = 1
        for w in range(W + 1):
            if board[0][w] == 0:
                break
            board[0][w] = 1

        for w in range(1, W + 1):
            for h in range(1, H + 1):
                if board[h][w] == 0:
                    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