結果
| 問題 |
No.1345 Beautiful BINGO
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-04-20 23:33:18 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 193 ms / 2,000 ms |
| コード長 | 1,727 bytes |
| コンパイル時間 | 4,149 ms |
| コンパイル使用メモリ | 143,868 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 18:02:16 |
| 合計ジャッジ時間 | 9,014 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 61 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
struct Node {
int y;
int v;
Node(int y = -1, int v = -1) {
this->y = y;
this->v = v;
}
bool operator>(const Node &n) const {
return v > n.v;
}
};
int main() {
int N, M;
cin >> N >> M;
int A[N][N];
for (int y = 0; y < N; ++y) {
for (int x = 0; x < N; ++x) {
cin >> A[y][x];
}
}
int ans = INT_MAX;
int L = (1 << N);
for (int mask = 0; mask < L; ++mask) {
for (int v = 0; v < 4; ++v) {
int B[N][N];
memcpy(B, A, sizeof(A));
int sum = 0;
int m = M;
for (int x = 0; x < N; ++x) {
if ((mask >> x & 1) == 0) continue;
--m;
for (int y = 0; y < N; ++y) {
sum += B[y][x];
B[y][x] = 0;
}
}
if (v >> 0 & 1) {
--m;
for (int i = 0; i < N; ++i) {
sum += B[i][i];
B[i][i] = 0;
}
}
if (v >> 1 & 1) {
--m;
for (int i = 0; i < N; ++i) {
sum += B[i][N - i - 1];
B[i][N - i - 1] = 0;
}
}
priority_queue <Node, vector<Node>, greater<Node>> pque;
for (int y = 0; y < N; ++y) {
int v = 0;
for (int x = 0; x < N; ++x) {
v += B[y][x];
}
pque.push(Node(y, v));
}
for (int i = 0; i < m && not pque.empty(); ++i) {
Node node = pque.top();
pque.pop();
sum += node.v;
}
ans = min(ans, sum);
}
}
cout << ans << endl;
return 0;
}
siman