結果

問題 No.1345 Beautiful BINGO
ユーザー kk
提出日時 2021-02-03 21:41:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 206,328 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-12 17:31:50
合計ジャッジ時間 9,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<vector<int> > a(n, vector<int>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      cin >> a[i][j];

  int ret = 1<<30;
  for (int mask = 0; mask < 1<<n; mask++) {
    for (int l = 0; l < 2; l++) {
      for (int r = 0; r < 2; r++) {
        vector<int> use(n);
        for (int i = 0; i < n; i++)
          if (mask & 1 << i)
            use[i] = (1<<n) - 1;
        if (l)
          for (int i = 0; i < n; i++)
            use[i] |= 1<<i;
        if (r)
          for (int i = 0; i < n; i++)
            use[i] |= 1<<(n-1-i);

        int cost = 0;
        for (int i = 0; i < n; i++)
          for (int j = 0; j < n; j++)
            if (use[i] & 1 << j)
              cost += a[i][j];
        
        int cnt = l + r + __builtin_popcountll(mask);
        if (cnt < m) {
          vector<int> sum(n);
          for (int j = 0; j < n; j++) {
            int tmp = 0;
            for (int i = 0; i < n; i++)
              if (!(use[i] & 1 << j))
                tmp += a[i][j];
            sum[j] = tmp;
          }
          sort(sum.begin(), sum.end());
          for (int i = 0; i < m - cnt; i++)
            cost += sum[n-1-i];
        }
        ret = min(ret, cost);
      }
    }
  }
  cout << ret << endl;
  
  return 0;
}
0