結果
問題 | No.1345 Beautiful BINGO |
ユーザー |
|
提出日時 | 2021-01-16 23:31:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 1,174 bytes |
コンパイル時間 | 2,012 ms |
コンパイル使用メモリ | 177,540 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-28 13:27:10 |
合計ジャッジ時間 | 9,688 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 61 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i = 0; i < (n); i++)using namespace std;typedef long long ll;#define bit(n,k) ((n>>k)&1)int main(){cin.tie(0);ios::sync_with_stdio(0);int N,M; cin >> N >> M;vector<vector<int>> A(N, vector<int> (N));rep(i,N)rep(j,N) cin >> A[i][j];int ans = 1e9;rep(i,1<<(N+2)){auto B = A;int cost = 0;rep(j,N+2)if(bit(i,j)){if(j == N){rep(k,N){cost += B[k][k];B[k][k] = 0;}}else if(j == N + 1){rep(k,N){cost += B[k][N-1-k];B[k][N-1-k] = 0;}}else{rep(k,N){cost += B[k][j];B[k][j] = 0;}}}vector<int> v;rep(j,N){int tmp = 0;rep(k,N) tmp += B[j][k];v.emplace_back(tmp);}sort(v.begin(), v.end());rep(j,M-__builtin_popcount(i)) cost += v[j];ans = min(ans, cost);}cout << ans << '\n';}