結果

問題 No.1345 Beautiful BINGO
ユーザー rlangevinrlangevin
提出日時 2023-03-03 08:58:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,918 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 81,308 KB
実行使用メモリ 76,372 KB
最終ジャッジ日時 2023-10-18 00:51:04
合計ジャッジ時間 30,493 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,352 KB
testcase_01 AC 41 ms
58,652 KB
testcase_02 AC 37 ms
53,352 KB
testcase_03 AC 38 ms
53,352 KB
testcase_04 AC 37 ms
53,352 KB
testcase_05 AC 65 ms
70,456 KB
testcase_06 AC 37 ms
53,352 KB
testcase_07 AC 88 ms
75,952 KB
testcase_08 AC 38 ms
53,352 KB
testcase_09 AC 38 ms
53,352 KB
testcase_10 AC 55 ms
65,988 KB
testcase_11 AC 66 ms
72,512 KB
testcase_12 AC 38 ms
53,352 KB
testcase_13 AC 87 ms
75,964 KB
testcase_14 AC 57 ms
66,268 KB
testcase_15 AC 38 ms
53,352 KB
testcase_16 AC 60 ms
68,556 KB
testcase_17 AC 41 ms
58,652 KB
testcase_18 AC 38 ms
53,352 KB
testcase_19 AC 41 ms
58,652 KB
testcase_20 AC 38 ms
53,352 KB
testcase_21 AC 42 ms
58,652 KB
testcase_22 AC 150 ms
75,808 KB
testcase_23 AC 1,891 ms
75,932 KB
testcase_24 AC 835 ms
75,820 KB
testcase_25 AC 121 ms
75,980 KB
testcase_26 AC 426 ms
75,864 KB
testcase_27 AC 1,876 ms
76,372 KB
testcase_28 AC 118 ms
75,964 KB
testcase_29 AC 433 ms
75,852 KB
testcase_30 AC 232 ms
75,808 KB
testcase_31 AC 157 ms
75,980 KB
testcase_32 AC 95 ms
75,964 KB
testcase_33 AC 1,876 ms
76,104 KB
testcase_34 AC 98 ms
75,908 KB
testcase_35 AC 98 ms
75,908 KB
testcase_36 AC 543 ms
76,008 KB
testcase_37 AC 66 ms
72,600 KB
testcase_38 AC 429 ms
75,848 KB
testcase_39 AC 1,918 ms
76,308 KB
testcase_40 AC 834 ms
76,112 KB
testcase_41 AC 443 ms
76,036 KB
testcase_42 AC 37 ms
53,352 KB
testcase_43 AC 37 ms
53,352 KB
testcase_44 AC 42 ms
58,652 KB
testcase_45 AC 40 ms
58,652 KB
testcase_46 AC 36 ms
53,352 KB
testcase_47 AC 37 ms
53,352 KB
testcase_48 AC 37 ms
53,352 KB
testcase_49 AC 37 ms
53,352 KB
testcase_50 AC 38 ms
53,352 KB
testcase_51 AC 41 ms
58,652 KB
testcase_52 AC 102 ms
75,544 KB
testcase_53 AC 1,893 ms
75,960 KB
testcase_54 AC 1,891 ms
75,988 KB
testcase_55 AC 1,876 ms
75,992 KB
testcase_56 AC 103 ms
75,548 KB
testcase_57 AC 1,817 ms
76,084 KB
testcase_58 AC 1,890 ms
75,988 KB
testcase_59 AC 1,877 ms
76,324 KB
testcase_60 AC 838 ms
75,960 KB
testcase_61 AC 1,893 ms
75,996 KB
testcase_62 AC 90 ms
75,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(n):
    cnt = 0
    while n:
        cnt += n & 1
        n >>= 1
    return cnt

def f(i, j):
    return i * N + j

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

ans = 10 ** 18
for s in range(1 << (N + 2)):
    c = popcount(s)
    if c > M:
        continue
    seen = [0] * (N * N)
    cnt = 0
    for i in range(N):
        for j in range(N):
            if (s >> i) & 1:
                seen[f(i, j)] = 1
                cnt += A[f(i, j)]
                continue
            if (s >> N) & 1 and i == j:
                seen[f(i, j)] = 1
                cnt += A[f(i, j)]
                continue
            if (s >> (N + 1)) & 1 and i + j == N - 1:
                seen[f(i, j)] = 1
                cnt += A[f(i, j)]
                continue
    L = [0] * N
    for i in range(N):
        for j in range(N):
            if seen[f(i, j)]:
                continue
            L[j] += A[f(i, j)]
    L.sort()
    ans = min(ans, cnt + sum(L[:M-c]))

print(ans)
0