結果

問題 No.506 限られたジャパリまん
ユーザー rpy3cpprpy3cpp
提出日時 2017-04-23 00:56:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,298 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,356 KB
最終ジャッジ日時 2023-09-10 12:53:48
合計ジャッジ時間 2,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,196 KB
testcase_01 AC 16 ms
8,340 KB
testcase_02 AC 17 ms
8,276 KB
testcase_03 AC 17 ms
8,300 KB
testcase_04 AC 31 ms
8,332 KB
testcase_05 AC 30 ms
8,284 KB
testcase_06 RE -
testcase_07 AC 18 ms
8,288 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 213 ms
8,304 KB
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 85 ms
8,348 KB
testcase_23 AC 54 ms
8,340 KB
testcase_24 AC 32 ms
8,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    H, W, K, P = map(int, input().split())
    xys = []
    names = []
    for k in range(K):
        x, y, name = input().rstrip().split()
        xys.append((int(x), int(y)))
        names.append(name)
    return H, W, K, P, xys, names

def solve(H, W, K, P, xys, names):
    record = 0
    sol_mask = 0
    mapp = [[1] * (W + 1) for _ in range(H + 1)]
    for mask in range(1 << K):
        score = calc_score(mask, mapp, H, W, K, P, xys)
        if score > record:
            record = score
            sol_mask = mask
    print_result(record, sol_mask, names)

def print_result(record, sol_mask, names):
    print(record % (10**9 + 7))
    if record:
        for i in range(len(names)):
            if (sol_mask & 1) == 0:
                print(names[i])
            sol_mask >>= 1

def calc_score(mask, mapp, H, W, K, P, xys):
    if bin(mask).count('1') != K - P:
        return 0
    pos = [i for i in range(K) if mask & (1 << i)]
    for p in pos:
        x, y = xys[p]
        mapp[x][y] = 0
    dp = [1] + [0] * (H + 1)
    for row in mapp:
        for y, c in enumerate(row):
            dp[y] = (dp[y] + dp[y - 1]) * c
    for p in pos:
        x, y = xys[p]
        mapp[x][y] = 1
    return dp[H]


H, W, K, P, xys, names = read_data()
solve(H, W, K, P, xys, names)
0