結果

問題 No.1345 Beautiful BINGO
コンテスト
ユーザー convexineq
提出日時 2021-01-16 23:46:28
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 916 ms / 2,000 ms
+ 449µs
コード長 593 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 69 ms
コンパイル使用メモリ 81,908 KB
実行使用メモリ 85,848 KB
最終ジャッジ日時 2026-10-07 18:56:43
合計ジャッジ時間 16,776 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]

N = (1<<(n+2))
cnt = [0]*N
for i in range(n+2):
    for j in range(1<<i):
        cnt[j+(1<<i)] = cnt[j]+1
ans = 10**9
for mask in range(N):
    cm = cnt[mask]
    if cm > m: continue
    res = [0]*n
    val = 0
    for i in range(n):
        for j in range(n):
            if mask>>j&1 or (j == i and mask>>n&1) or (j == n-1-i and mask>>(n+1)&1):
                val += a[i][j]
            else:
                res[i] += a[i][j]
    res.sort()
    val += sum(res[:m-cm])
    ans = min(ans,val)
print(ans)
0