結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,336 KB
testcase_01 AC 17 ms
8,292 KB
testcase_02 AC 16 ms
8,324 KB
testcase_03 AC 16 ms
8,432 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
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 WA -
testcase_23 WA -
testcase_24 AC 33 ms
8,340 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)
    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