結果
問題 |
No.1345 Beautiful BINGO
|
ユーザー |
![]() |
提出日時 | 2021-01-16 13:35:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,546 bytes |
コンパイル時間 | 2,262 ms |
コンパイル使用メモリ | 198,000 KB |
最終ジャッジ日時 | 2025-01-17 22:08:54 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 WA * 19 TLE * 8 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n - 1); i >= 0; i--) #define ALL(v) v.begin(), v.end() using namespace std; using P = pair<int, int>; typedef long long ll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, m; cin >> n >> m; ll ans = (1LL << 60); vector<vector<int>> A(n, vector<int>(n)); rep(i, n) rep(j, n) cin >> A[i][j]; for (int bit = 1; bit < (1 << (2 * n + 2)); bit++){ int d = __builtin_popcount(bit); vector<vector<int>> cnt(n, vector<int>(n, 0)); if(d != m)continue; ll res = 0; rep(i, 2 *n +2){ if(bit & (1 << i)){ if(i < n){ rep(j, n){ res += A[i][j]; cnt[i][j]++; } }else if(i >= n && i < 2 * n){ rep(j, n){ res += A[j][i - n]; cnt[j][i- n]++; } }else{ if(i == 2 * n){ rep(j, n){ res += A[j][j]; cnt[j][j]++; } }else{ rep(j, n){ res += A[j][n -1- j]; cnt[j][n -1- j]++; } } } } } rep(i, n){ rep(j, n){ if(cnt[i][j] > 1)res -= A[i][j] * (cnt[i][j] - 1); } } chmin(ans, res); } cout << ans << endl; }