結果

問題 No.1345 Beautiful BINGO
ユーザー sakasu1sakasu1
提出日時 2021-01-23 14:50:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 174,840 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-09 19:57:58
合計ジャッジ時間 8,144 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 19 ms
6,944 KB
testcase_23 AC 388 ms
6,944 KB
testcase_24 AC 177 ms
6,940 KB
testcase_25 AC 10 ms
6,940 KB
testcase_26 AC 80 ms
6,940 KB
testcase_27 AC 337 ms
6,940 KB
testcase_28 AC 9 ms
6,940 KB
testcase_29 AC 78 ms
6,944 KB
testcase_30 AC 38 ms
6,940 KB
testcase_31 AC 20 ms
6,940 KB
testcase_32 AC 4 ms
6,944 KB
testcase_33 AC 344 ms
6,944 KB
testcase_34 AC 6 ms
6,944 KB
testcase_35 AC 6 ms
6,944 KB
testcase_36 AC 103 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 78 ms
6,940 KB
testcase_39 AC 352 ms
6,940 KB
testcase_40 AC 168 ms
6,944 KB
testcase_41 AC 74 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 1 ms
6,940 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 70 ms
6,940 KB
testcase_53 AC 356 ms
6,940 KB
testcase_54 AC 359 ms
6,944 KB
testcase_55 AC 353 ms
6,940 KB
testcase_56 AC 73 ms
6,944 KB
testcase_57 AC 318 ms
6,940 KB
testcase_58 AC 354 ms
6,944 KB
testcase_59 AC 342 ms
6,944 KB
testcase_60 AC 136 ms
6,944 KB
testcase_61 AC 367 ms
6,944 KB
testcase_62 AC 71 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,j,k,n,m;
  cin >> n >> m;
  int a[17][17];
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  int ans=1000000000;
  for(i=0;i<(1<<(n+2));i++){
    int b[17][17];
    for(j=0;j<n;j++){
      for(k=0;k<n;k++){
        b[j][k]=0;
      }
    }
    int sum=0,count=0;
    for(j=0;j<n;j++){
      if(!(i&(1<<j))){
        continue;
      }
      count++;
      for(k=0;k<n;k++){
        sum+=a[j][k],b[j][k]=1;
      }
    }
    if(i&(1<<n)){
      count++;
      for(j=0;j<n;j++){
        if(b[j][j]==1){
          continue;
        }
        sum+=a[j][j],b[j][j]=1;
      }
    }
    if(i&(1<<(n+1))){
      count++;
      for(j=0;j<n;j++){
        if(b[j][n-j-1]==1){
          continue;
        }
        sum+=a[j][n-j-1],b[j][n-j-1]=1;
      }
    }
    if(count>=m){
      ans=min(ans,sum);
      continue;
    }
    vector<int> x;
    for(j=0;j<n;j++){
      int sum1=0;
      for(k=0;k<n;k++){
        if(b[k][j]==0){
          sum1+=a[k][j],b[k][j]=1;
        }
      }
      x.push_back(sum1);
    }
    sort(x.begin(),x.end());
    for(j=0;j<m-count;j++){
      sum+=x[j];
    }
    ans=min(ans,sum);
  }
  cout << ans << endl;
}
0