結果

問題 No.1345 Beautiful BINGO
ユーザー sakasu1sakasu1
提出日時 2021-01-23 14:50:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 170,052 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-29 01:45:35
合計ジャッジ時間 10,475 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 21 ms
4,380 KB
testcase_23 AC 390 ms
4,376 KB
testcase_24 AC 183 ms
4,376 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 87 ms
4,376 KB
testcase_27 AC 368 ms
4,376 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 87 ms
4,380 KB
testcase_30 AC 42 ms
4,376 KB
testcase_31 AC 20 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 370 ms
4,380 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 103 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 87 ms
4,380 KB
testcase_39 AC 384 ms
4,376 KB
testcase_40 AC 184 ms
4,376 KB
testcase_41 AC 79 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,384 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 67 ms
4,380 KB
testcase_53 AC 386 ms
4,380 KB
testcase_54 AC 389 ms
4,376 KB
testcase_55 AC 383 ms
4,376 KB
testcase_56 AC 68 ms
4,376 KB
testcase_57 AC 346 ms
4,376 KB
testcase_58 AC 385 ms
4,376 KB
testcase_59 AC 368 ms
4,376 KB
testcase_60 AC 140 ms
4,376 KB
testcase_61 AC 386 ms
4,380 KB
testcase_62 AC 68 ms
4,376 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