結果

問題 No.1345 Beautiful BINGO
ユーザー hayatenhayaten
提出日時 2021-01-16 14:52:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,962 bytes
コンパイル時間 2,827 ms
コンパイル使用メモリ 210,404 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2024-05-05 17:31:31
合計ジャッジ時間 8,453 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,016 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 31 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 32 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 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 307 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1,590 ms
5,376 KB
testcase_26 TLE -
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};

vector<ll> sum_result(const vector<vector<ll>> &A, int n){
  vector<ll> sum(2 * n + 2);
  rep(i, 2 *n +2){
    if(i < n){
      rep(j, n){
        sum[i] += A[i][j];
      }
    }else if(i >= n && i < 2 * n){
      rep(j, n){
        sum[i] += A[j][i - n];
      }
    }else{
      if(i == 2 * n){
        rep(j, n){
          sum[i] += A[j][j];
        }
      }else{
        rep(j, n){
          sum[i] += A[j][n -1- j];
        }
      }
    }
  }
  return sum;
}

int main() {
  int n, m;
  cin >> n >> m;
  ll ans = (1LL << 50);
  vector<vector<ll>> A(n, vector<ll>(n));
  rep(i, n) rep(j, n) cin >> A[i][j];
  vector<ll> sum = sum_result(A, n);
  for (int bit = 1; bit < (1 << (2 * n + 2)); bit++){
    int d = __builtin_popcount(bit);
    if(d != m)continue;
    ll res = 0;
    vector<int> cnt_i(n);
    vector<int> cnt_j(n);
    vector<vector<int>> cnt(n, vector<int>(n, 0));
    rep(i, 2 *n +2){
      if(bit & (1 << i)){
        res += sum[i];
        if(i < n){
          cnt_i[i]++;
        }else if(i >= n && i < 2 * n)  {
          cnt_j[i - n]++;
        }else{
          if(i == 2 * n){
            rep(j, n){
              cnt[j][j]++;
            }
          }else{
            rep(j, n){
              cnt[j][n - 1 - j]++;
            }
          }
        }
      }
    }
    rep(i, n){
      rep(j, n){
        int f = cnt_i[i] + cnt_j[j] + cnt[i][j];
        if(f > 0)res -= (f -1) * A[i][j];
      }
    }
    chmin(ans, res);
  }
  cout << ans << endl;
}
0