結果

問題 No.1345 Beautiful BINGO
ユーザー LayCurseLayCurse
提出日時 2021-01-16 13:10:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 4,403 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 215,220 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 23:49:07
合計ジャッジ時間 7,108 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int M;
int A[16][16];
int b[16][16];
int c[16];
int main(){
  int mask;
  wmem = memarr;
  int res = 1073709056;
  int tmp;
  int ok;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    int KL2GvlyY;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      for(KL2GvlyY=(0);KL2GvlyY<(N);KL2GvlyY++){
        rd(A[Lj4PdHRW][KL2GvlyY]);
      }
    }
  }
  for(mask=(0);mask<(1<<(N+2));mask++){
    int i;
    tmp = 0;
    ok = 0;
    for(i=(0);i<(N+2);i++){
      if(((mask) &(1<<(i)))){
        ok++;
      }
    }
    for(i=(0);i<(N);i++){
      int j;
      for(j=(0);j<(N);j++){
        b[i][j] = A[i][j];
      }
    }
    for(i=(0);i<(N);i++){
      if(((mask) &(1<<(i)))){
        int j;
        for(j=(0);j<(N);j++){
          tmp += b[i][j];
          b[i][j] = 0;
        }
      }
    }
    if(((mask) &(1<<(N)))){
      for(i=(0);i<(N);i++){
        tmp += b[i][i];
        b[i][i] = 0;
      }
    }
    if(((mask) &(1<<(N+1)))){
      for(i=(0);i<(N);i++){
        tmp += b[N-1-i][i];
        b[N-1-i][i] = 0;
      }
    }
    for(i=(0);i<(N);i++){
      {
        int jPV_0s1p;
        remove_reference<decltype(b[jPV_0s1p][i])>::type BUotOFBp;
        int Q5rsz4fz = 0;
        if((0) > ((N)-1)){
          BUotOFBp = 0;
        }
        else{
          for(jPV_0s1p = 0; jPV_0s1p <= (N)-1; jPV_0s1p++){
            if(Q5rsz4fz == 0){
              BUotOFBp = b[jPV_0s1p][i];
              Q5rsz4fz = 1;
              continue;
            }
            BUotOFBp += b[jPV_0s1p][i];
          }
        }
        c[i] =BUotOFBp;
      }
    }
    sortA_L(N, c);
    for(i=(0);i<(M-ok);i++){
      tmp += c[i];
    }
    chmin(res, tmp);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20210103-1 [bug fixed 1]

// --- original code ---
// int N, M, A[16][16], b[16][16], c[16];
// {
//   int res = int_inf, tmp, ok;
//   rd(N,M,A(N,N));
//   rep(mask,1<<(N+2)){
//     tmp = 0;
//     ok = 0;
//     rep(i,N+2) if(BIT_ith(mask,i)) ok++;
//     rep(i,N) rep(j,N) b[i][j] = A[i][j];
//     rep(i,N) if(BIT_ith(mask,i)) rep(j,N) tmp += b[i][j], b[i][j] = 0;
//     if(BIT_ith(mask,N)) rep(i,N) tmp += b[i][i], b[i][i] = 0;
//     if(BIT_ith(mask,N+1)) rep(i,N) tmp += b[N-1-i][i], b[N-1-i][i] = 0;
//     rep(i,N) c[i] = sum[j,0,N](b[j][i]);
//     sortA(N, c);
//     rep(i, M-ok) tmp += c[i];
//     res <?= tmp;
//   }
//   wt(res);
// }
0