結果

問題 No.1345 Beautiful BINGO
ユーザー SSRSSSRS
提出日時 2021-01-16 13:25:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,241 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 175,668 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 15:24:39
合計ジャッジ時間 4,641 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
int main(){
  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 ans = INF;
  for (int i = 0; i < 2; i++){
    for (int j = 0; j < 2; j++){
      int sum = 0;
      vector<vector<int>> B = A;
      for (int k = 0; k < N; k++){
        for (int l = 0; l < N; l++){
          if (i == 1 && k == l || j == 1 && k + l == N - 1){
            sum += A[k][l];
            B[k][l] = 0;
          }
        }
      }
      for (int k = 0; k < (1 << N); k++){
        int cnt = i + j + __builtin_popcount(k);
        if (M - cnt >= 0 && M - cnt <= N){
          vector<int> c(N, 0);
          int add = 0;
          for (int l = 0; l < N; l++){
            for (int m = 0; m < N; m++){
              if (!(k >> l & 1)){
                c[m] += B[l][m];
              } else {
                add += B[l][m];
              }
            }
          }
          sort(c.begin(), c.end());
          for (int l = 0; l < M - cnt; l++){
            add += c[i];
          }
          ans = min(ans, sum + add);
        }
      }
    }
  }
  cout << ans << endl;
}
0