結果
| 問題 |
No.1345 Beautiful BINGO
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-16 13:48:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,290 bytes |
| コンパイル時間 | 628 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 159,872 KB |
| 最終ジャッジ日時 | 2024-11-27 14:33:01 |
| 合計ジャッジ時間 | 52,298 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 TLE * 16 |
ソースコード
import itertools
from copy import deepcopy
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
def make_table(t, slash, backslash):
table = deepcopy(A)
solved = 0
for y, b in enumerate(t):
if b:
for x in range(N):
solved += table[y][x]
table[y][x] = 0
if slash:
for i in range(N):
solved += table[i][i]
table[i][i] = 0
if backslash:
for i in range(N):
solved += table[N - i - 1][i]
table[N - i - 1][i] = 0
return table, solved
ans = 100 * N * N
# 横と斜めは全列挙
for t in itertools.product((0, 1), repeat=N):
row = t.count(1)
if row > M:
continue
for slash, backslash in itertools.product((0, 1), repeat=2):
col = M - row - slash - backslash # 削るべき列数
if not 0 <= col <= N:
continue
table, solved = make_table(t, slash, backslash)
additional_solved = [0] * N
# 縦のうれしい順に選ぶ
for i in range(N):
additional_solved[i] = sum(table[j][i] for j in range(N))
additional_solved.sort()
solved += sum(additional_solved[:col])
ans = min(ans, solved)
print(ans)