結果

問題 No.1345 Beautiful BINGO
ユーザー rlangevinrlangevin
提出日時 2023-03-03 12:29:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,915 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 81,620 KB
実行使用メモリ 76,380 KB
最終ジャッジ日時 2023-10-18 00:56:19
合計ジャッジ時間 24,658 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,372 KB
testcase_01 AC 41 ms
58,672 KB
testcase_02 AC 38 ms
53,372 KB
testcase_03 AC 38 ms
53,372 KB
testcase_04 AC 37 ms
53,372 KB
testcase_05 AC 68 ms
72,464 KB
testcase_06 AC 38 ms
53,372 KB
testcase_07 AC 91 ms
75,968 KB
testcase_08 AC 37 ms
53,372 KB
testcase_09 AC 37 ms
53,372 KB
testcase_10 AC 55 ms
66,008 KB
testcase_11 AC 57 ms
66,292 KB
testcase_12 AC 38 ms
53,372 KB
testcase_13 AC 91 ms
75,968 KB
testcase_14 AC 41 ms
58,672 KB
testcase_15 AC 37 ms
53,372 KB
testcase_16 AC 60 ms
68,576 KB
testcase_17 AC 40 ms
58,672 KB
testcase_18 AC 37 ms
53,372 KB
testcase_19 AC 41 ms
58,672 KB
testcase_20 AC 37 ms
53,372 KB
testcase_21 AC 37 ms
53,372 KB
testcase_22 AC 48 ms
69,860 KB
testcase_23 AC 77 ms
74,892 KB
testcase_24 AC 109 ms
76,088 KB
testcase_25 AC 120 ms
75,996 KB
testcase_26 AC 434 ms
75,872 KB
testcase_27 AC 1,886 ms
76,380 KB
testcase_28 AC 98 ms
76,028 KB
testcase_29 AC 428 ms
75,840 KB
testcase_30 AC 67 ms
75,392 KB
testcase_31 AC 98 ms
76,088 KB
testcase_32 AC 95 ms
76,080 KB
testcase_33 AC 1,893 ms
76,124 KB
testcase_34 AC 64 ms
72,492 KB
testcase_35 AC 81 ms
75,764 KB
testcase_36 AC 543 ms
76,028 KB
testcase_37 AC 66 ms
72,620 KB
testcase_38 AC 423 ms
75,956 KB
testcase_39 AC 1,915 ms
76,320 KB
testcase_40 AC 852 ms
76,080 KB
testcase_41 AC 448 ms
76,052 KB
testcase_42 AC 37 ms
53,372 KB
testcase_43 AC 37 ms
53,372 KB
testcase_44 AC 42 ms
58,672 KB
testcase_45 AC 40 ms
58,672 KB
testcase_46 AC 37 ms
53,372 KB
testcase_47 AC 37 ms
53,372 KB
testcase_48 AC 37 ms
53,372 KB
testcase_49 AC 37 ms
53,372 KB
testcase_50 AC 37 ms
53,372 KB
testcase_51 AC 37 ms
53,372 KB
testcase_52 AC 102 ms
75,564 KB
testcase_53 AC 1,867 ms
75,984 KB
testcase_54 AC 293 ms
76,160 KB
testcase_55 AC 724 ms
76,264 KB
testcase_56 AC 105 ms
75,564 KB
testcase_57 AC 1,808 ms
76,104 KB
testcase_58 AC 1,588 ms
75,972 KB
testcase_59 AC 1,888 ms
76,348 KB
testcase_60 AC 843 ms
75,980 KB
testcase_61 AC 1,024 ms
76,068 KB
testcase_62 AC 89 ms
75,472 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 or c + N < 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