結果
| 問題 |
No.1345 Beautiful BINGO
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-03-03 12:29:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,049 bytes |
| コンパイル時間 | 526 ms |
| コンパイル使用メモリ | 82,152 KB |
| 実行使用メモリ | 77,072 KB |
| 最終ジャッジ日時 | 2025-01-18 04:00:39 |
| 合計ジャッジ時間 | 26,966 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 57 TLE * 4 |
ソースコード
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)
rlangevin