結果

問題 No.1345 Beautiful BINGO
ユーザー H3PO4H3PO4
提出日時 2021-01-16 14:06:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,166 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 49,492 KB
最終ジャッジ日時 2024-05-05 16:16:25
合計ジャッジ時間 19,681 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 479 ms
49,492 KB
testcase_01 AC 483 ms
44,560 KB
testcase_02 AC 471 ms
44,644 KB
testcase_03 AC 468 ms
44,380 KB
testcase_04 AC 470 ms
44,244 KB
testcase_05 AC 479 ms
44,500 KB
testcase_06 AC 459 ms
44,436 KB
testcase_07 AC 500 ms
44,376 KB
testcase_08 AC 457 ms
44,120 KB
testcase_09 AC 465 ms
44,380 KB
testcase_10 AC 470 ms
44,376 KB
testcase_11 AC 491 ms
44,372 KB
testcase_12 AC 477 ms
44,120 KB
testcase_13 AC 511 ms
44,376 KB
testcase_14 AC 470 ms
44,128 KB
testcase_15 AC 487 ms
44,504 KB
testcase_16 AC 473 ms
44,632 KB
testcase_17 AC 481 ms
44,508 KB
testcase_18 AC 475 ms
44,636 KB
testcase_19 AC 474 ms
44,376 KB
testcase_20 AC 480 ms
44,120 KB
testcase_21 AC 467 ms
44,376 KB
testcase_22 AC 469 ms
43,996 KB
testcase_23 AC 496 ms
44,116 KB
testcase_24 AC 517 ms
44,384 KB
testcase_25 AC 758 ms
44,120 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import numpy as np

N, M = map(int, input().split())
A = np.array([list(map(int, input().split())) for _ in range(N)])


def make_table(t, slash, backslash):
    fancy = np.nonzero(t)
    table = A.copy()
    solved = 0

    solved += np.sum(table[fancy, :])
    table[fancy, :] = 0

    if slash:
        for i in range(N):
            solved += table[i, i]
            table[i, i] = 0
    if backslash:
        for i in range(N):
            solved += table[N - i - 1, i]
            table[N - i - 1, i] = 0

    return table, solved


ans = 100 * N * N

# 横と斜めは全列挙
for t in itertools.product((0, 1), repeat=N):
    row = t.count(1)
    if not M - N - 2 <= row <= M:
        continue
    for slash, backslash in ((0, 0), (1, 0), (0, 1), (1, 1)):
        col = M - row - slash - backslash  # 削るべき列数
        if not 0 <= col <= N:
            continue
        table, solved = make_table(t, slash, backslash)

        # 縦のうれしい順に選ぶ
        additional_solved = np.sum(table, axis=0)
        additional_solved.sort()
        solved += sum(additional_solved[:col])
        ans = min(ans, solved)
print(ans)
0