結果

問題 No.1345 Beautiful BINGO
ユーザー hayatenhayaten
提出日時 2021-01-16 13:35:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 206,172 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-05-05 15:35:08
合計ジャッジ時間 5,926 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,448 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 79 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 80 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0