結果

問題 No.1345 Beautiful BINGO
ユーザー mkawa2mkawa2
提出日時 2023-05-10 15:08:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,419 ms / 2,000 ms
コード長 2,019 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 82,296 KB
実行使用メモリ 77,644 KB
最終ジャッジ日時 2024-11-26 20:33:59
合計ジャッジ時間 23,204 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,496 KB
testcase_01 AC 41 ms
53,336 KB
testcase_02 AC 40 ms
53,212 KB
testcase_03 AC 41 ms
52,952 KB
testcase_04 AC 41 ms
53,764 KB
testcase_05 AC 59 ms
65,748 KB
testcase_06 AC 40 ms
53,244 KB
testcase_07 AC 100 ms
76,664 KB
testcase_08 AC 40 ms
53,468 KB
testcase_09 AC 39 ms
52,980 KB
testcase_10 AC 49 ms
61,696 KB
testcase_11 AC 55 ms
65,120 KB
testcase_12 AC 41 ms
53,216 KB
testcase_13 AC 100 ms
77,004 KB
testcase_14 AC 45 ms
59,720 KB
testcase_15 AC 40 ms
54,300 KB
testcase_16 AC 48 ms
61,744 KB
testcase_17 AC 40 ms
54,156 KB
testcase_18 AC 40 ms
53,480 KB
testcase_19 AC 41 ms
53,932 KB
testcase_20 AC 40 ms
53,552 KB
testcase_21 AC 40 ms
53,668 KB
testcase_22 AC 110 ms
76,396 KB
testcase_23 AC 491 ms
76,504 KB
testcase_24 AC 301 ms
76,784 KB
testcase_25 AC 150 ms
77,228 KB
testcase_26 AC 381 ms
76,864 KB
testcase_27 AC 1,376 ms
77,644 KB
testcase_28 AC 134 ms
76,948 KB
testcase_29 AC 372 ms
76,932 KB
testcase_30 AC 137 ms
76,656 KB
testcase_31 AC 147 ms
76,932 KB
testcase_32 AC 113 ms
77,368 KB
testcase_33 AC 1,384 ms
77,260 KB
testcase_34 AC 99 ms
76,392 KB
testcase_35 AC 113 ms
76,596 KB
testcase_36 AC 659 ms
76,852 KB
testcase_37 AC 93 ms
76,636 KB
testcase_38 AC 370 ms
77,172 KB
testcase_39 AC 1,405 ms
77,440 KB
testcase_40 AC 676 ms
76,888 KB
testcase_41 AC 422 ms
77,204 KB
testcase_42 AC 40 ms
52,744 KB
testcase_43 AC 40 ms
53,480 KB
testcase_44 AC 41 ms
53,444 KB
testcase_45 AC 41 ms
53,884 KB
testcase_46 AC 40 ms
53,012 KB
testcase_47 AC 39 ms
53,240 KB
testcase_48 AC 41 ms
54,252 KB
testcase_49 AC 41 ms
53,620 KB
testcase_50 AC 40 ms
52,996 KB
testcase_51 AC 41 ms
53,140 KB
testcase_52 AC 495 ms
76,480 KB
testcase_53 AC 1,419 ms
77,080 KB
testcase_54 AC 638 ms
77,248 KB
testcase_55 AC 863 ms
76,988 KB
testcase_56 AC 501 ms
76,600 KB
testcase_57 AC 1,326 ms
76,896 KB
testcase_58 AC 1,271 ms
77,248 KB
testcase_59 AC 1,386 ms
77,352 KB
testcase_60 AC 769 ms
77,108 KB
testcase_61 AC 1,015 ms
77,144 KB
testcase_62 AC 498 ms
76,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# md = 10**9+7
md = 998244353

def popcnt(a): return bin(a).count("1")

def f(s, m):
    if m == 0: return 0
    if m < 0 or m > n: return inf
    cc = []
    for j in range(n):
        cur = 0
        for i in range(n):
            if s >> i & 1: continue
            cur += a[i][j]
        cc.append(cur)
    cc.sort()
    return sum(cc[:m])

n, m = LI()
ori = LLI(n)

ans = inf

a = [r[:] for r in ori]
pre = 0
for s in range(1 << n):
    row = 0
    for i in range(n):
        if s >> i & 1: row += sum(a[i])
    ans=min(ans,f(s,m-popcnt(s))+pre+row)

a = [r[:] for r in ori]
pre = 0
for i in range(n):
    pre += a[i][i]
    a[i][i] = 0
for s in range(1 << n):
    row = 0
    for i in range(n):
        if s >> i & 1: row += sum(a[i])
    ans=min(ans,f(s,m-popcnt(s)-1)+pre+row)

a = [r[:] for r in ori]
pre = 0
for i in range(n):
    pre += a[i][n-1-i]
    a[i][n-1-i] = 0
for s in range(1 << n):
    row = 0
    for i in range(n):
        if s >> i & 1: row += sum(a[i])
    ans=min(ans,f(s,m-popcnt(s)-1)+pre+row)

a = [r[:] for r in ori]
pre = 0
for i in range(n):
    pre += a[i][i]
    a[i][i] = 0
    pre += a[i][n-1-i]
    a[i][n-1-i] = 0
for s in range(1 << n):
    row = 0
    for i in range(n):
        if s >> i & 1: row += sum(a[i])
    ans=min(ans,f(s,m-popcnt(s)-2)+pre+row)

print(ans)
0