結果

問題 No.1345 Beautiful BINGO
コンテスト
ユーザー rlangevin
提出日時 2023-03-03 08:56:55
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
(最新)
TLE  
(最初)
実行時間 1,539 ms / 2,000 ms
コード長 991 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 148 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 82,176 KB
最終ジャッジ日時 2026-04-06 11:40:41
合計ジャッジ時間 24,233 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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