結果
問題 | No.1345 Beautiful BINGO |
ユーザー |
![]() |
提出日時 | 2021-03-02 06:17:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 560 ms / 2,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 198,944 KB |
最終ジャッジ日時 | 2025-01-19 09:13:55 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 pb push_backtypedef long long ll;int main() {cin.tie(0); ios::sync_with_stdio(false);int N, M; cin >> N >> M;int A[N][N];rep(i, N) rep(j, N) cin >> A[i][j];int ans = 1000000;rep(S, 1<<(N+2)) {int cnt = 0;bool flag[N][N];rep(i, N) rep(j, N) flag[i][j] = false;rep(i, N+2) if ((S>>i)&1) {cnt++;if (i<N) rep(j, N) flag[j][i] = true;else if (i==N) rep(j, N) flag[j][j] = true;else rep(j, N) flag[j][N-1-j] = true;}if (cnt>M) continue;int cand = 0;rep(i, N) rep(j, N) if (flag[i][j]) cand += A[i][j];vector<int> needs;rep(i, N) {int need = 0;rep(j, N) if (!flag[i][j]) need += A[i][j];needs.pb(need);}sort(needs.begin(), needs.end());rep(i, M-cnt) cand += needs[i];ans = min(ans, cand);}cout << ans << endl;}