結果

問題 No.1345 Beautiful BINGO
ユーザー rlangevin
提出日時 2023-03-03 08:56:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 991 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-09-17 21:51:54
合計ジャッジ時間 35,621 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

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

N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(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 for i in range(N)]
    cnt = 0
    for i in range(N):
        for j in range(N):
            if (s >> i) & 1:
                seen[i][j] = 1
                cnt += A[i][j]
                continue
            if (s >> N) & 1 and i == j:
                seen[i][j] = 1
                cnt += A[i][j]
                continue
            if (s >> (N + 1)) & 1 and i + j == N - 1:
                seen[i][j] = 1
                cnt += A[i][j]
                continue
    L = [0] * N
    for i in range(N):
        for j in range(N):
            if seen[i][j]:
                continue
            L[j] += A[i][j]
    L.sort()
    ans = min(ans, cnt + sum(L[:M-c]))

print(ans)
0