結果
問題 |
No.1345 Beautiful BINGO
|
ユーザー |
![]() |
提出日時 | 2021-01-16 13:19:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 918 ms / 2,000 ms |
コード長 | 970 bytes |
コンパイル時間 | 2,127 ms |
コンパイル使用メモリ | 206,436 KB |
最終ジャッジ日時 | 2025-01-17 21:52:44 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 61 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int main(){ int N,M; cin>>N>>M; vector A(N,vector<int>(N)); rep(i,N){ rep(j,N){ cin>>A[i][j]; } } int ans = Inf; rep(i,1<<(N+2)){ vector<vector<bool>> B(N,vector<bool>(N,false)); int cur = 0; int t = 0; rep(j,N){ if((i>>j)&1){ rep(k,N){ B[j][k] = true; cur += A[j][k]; } t++; } } if((i>>N)&1){ rep(j,N){ if(B[j][j])continue; B[j][j] = true; cur += A[j][j]; } t++; } if((i>>(N+1))&1){ rep(j,N){ if(B[j][N-1-j])continue; B[j][N-1-j] = true; cur += A[j][N-1-j]; } t++; } if(M-t>N)continue; vector<int> X(N,0); rep(j,N){ rep(k,N){ if(B[j][k])continue; X[k] += A[j][k]; } } sort(X.begin(),X.end()); rep(j,M-t){ cur += X[j]; } ans = min(ans,cur); } cout<<ans<<endl; return 0; }