結果
| 問題 |
No.1345 Beautiful BINGO
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-01-16 16:52:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 442 ms / 2,000 ms |
| コード長 | 1,343 bytes |
| コンパイル時間 | 2,153 ms |
| コンパイル使用メモリ | 195,868 KB |
| 最終ジャッジ日時 | 2025-01-17 23:42:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 61 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
short a[16][16];
short cs[16];
bool use[16][16];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
rep(i, n) rep(j, n) cin >> a[i][j];
short ans = 30000;
rep(s, 1 << n + 2) {
rep(i, n) rep(j, n) use[i][j] = false;
rep(i, n) if (s >> i & 1) rep(j, n) use[i][j] = true;
if (s >> n & 1) rep(i, n) use[i][i] = true;
if (s >> n + 1 & 1) rep(i, n) use[n-1-i][i] = true;
short score = 0;
rep(i, n) rep(j, n) score += use[i][j] * a[i][j];
rep(i, n) cs[i] = 0;
rep(i, n) rep(j, n) if (!use[i][j]) cs[j] += a[i][j];
sort(cs, cs + n);
int idx = 0;
short cnt = __builtin_popcount(s);
while(cnt < m && idx < n) score += cs[idx++], cnt++;
if (cnt == m) chmin(ans, score);
}
cout << ans << endl;
}
Kude