結果

問題 No.1345 Beautiful BINGO
ユーザー H3PO4H3PO4
提出日時 2021-01-16 13:48:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,290 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 87,680 KB
最終ジャッジ日時 2024-05-05 15:52:03
合計ジャッジ時間 7,754 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,520 KB
testcase_01 AC 45 ms
54,912 KB
testcase_02 AC 40 ms
53,632 KB
testcase_03 AC 44 ms
54,400 KB
testcase_04 AC 40 ms
53,376 KB
testcase_05 AC 102 ms
77,312 KB
testcase_06 AC 41 ms
53,376 KB
testcase_07 AC 132 ms
77,952 KB
testcase_08 AC 40 ms
53,760 KB
testcase_09 AC 41 ms
53,632 KB
testcase_10 AC 63 ms
67,968 KB
testcase_11 AC 68 ms
69,504 KB
testcase_12 AC 41 ms
54,144 KB
testcase_13 AC 130 ms
78,080 KB
testcase_14 AC 44 ms
54,912 KB
testcase_15 AC 39 ms
54,016 KB
testcase_16 AC 63 ms
67,968 KB
testcase_17 AC 43 ms
55,168 KB
testcase_18 AC 41 ms
53,888 KB
testcase_19 AC 42 ms
55,040 KB
testcase_20 AC 41 ms
53,504 KB
testcase_21 AC 40 ms
53,888 KB
testcase_22 AC 54 ms
64,256 KB
testcase_23 AC 97 ms
76,288 KB
testcase_24 AC 177 ms
77,912 KB
testcase_25 AC 304 ms
79,624 KB
testcase_26 AC 1,800 ms
81,280 KB
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
from copy import deepcopy

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


def make_table(t, slash, backslash):
    table = deepcopy(A)
    solved = 0
    for y, b in enumerate(t):
        if b:
            for x in range(N):
                solved += table[y][x]
                table[y][x] = 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 row > M:
        continue
    for slash, backslash in itertools.product((0, 1), repeat=2):
        col = M - row - slash - backslash  # 削るべき列数
        if not 0 <= col <= N:
            continue
        table, solved = make_table(t, slash, backslash)

        additional_solved = [0] * N

        # 縦のうれしい順に選ぶ
        for i in range(N):
            additional_solved[i] = sum(table[j][i] for j in range(N))
        additional_solved.sort()
        solved += sum(additional_solved[:col])
        ans = min(ans, solved)
print(ans)
0