結果
問題 |
No.1345 Beautiful BINGO
|
ユーザー |
|
提出日時 | 2021-01-16 13:59:39 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,148 bytes |
コンパイル時間 | 875 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 87,496 KB |
最終ジャッジ日時 | 2024-11-27 14:52:36 |
合計ジャッジ時間 | 75,112 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 45 TLE * 16 |
ソースコード
import itertools import numpy as np N, M = map(int, input().split()) A = np.array([list(map(int, input().split())) for _ in range(N)]) def make_table(t, slash, backslash): fancy = np.nonzero(t) table = A.copy() solved = 0 solved += np.sum(table[fancy, :]) table[fancy, :] = 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 ((0, 0), (1, 0), (0, 1), (1, 1)): col = M - row - slash - backslash # 削るべき列数 if not 0 <= col <= N: continue table, solved = make_table(t, slash, backslash) # 縦のうれしい順に選ぶ additional_solved = np.sum(table, axis=0) additional_solved.sort() solved += sum(additional_solved[:col]) ans = min(ans, solved) print(ans)