結果

問題 No.1345 Beautiful BINGO
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-01-14 00:30:52
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 2,211 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 165,632 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 06:38:12
合計ジャッジ時間 8,058 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ll n,m;
  cin>>n>>m;
  vector<vector<ll>> s(n,vector<ll>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>s[i][j];
    }
  }
  ll ans=inf;
  for(int a=0;a<2;a++){
    for(int b=0;b<2;b++){
      ll p=0;
      ll c=m-a-b;
      auto dp=s;
      if(a){
        for(int i=0;i<n;i++){
          p+=dp[i][i];
          dp[i][i]=0;
          p+=dp[i][i];
        }
      }
      if(b){
        for(int i=0;i<n;i++){
          p+=dp[i][n-i-1];
          dp[i][n-i-1]=0;
          p+=dp[i][n-i-1];
        }
      }
      vector<ll> f(n);
      for(int i=0;i<n;i++){
      ll tmp=0;
        for(int j=0;j<n;j++){
          tmp+=dp[i][j];
        }
        f[i]=tmp;
      }
      for(int i=0;i<(1<<n);i++){
        ll e=c;
        ll tmp=0;
        ll o=i;
        for(int j=0;j<n;j++){
          if(o%2==1){
            tmp+=f[j];
            e--;
          }
          o/=2;
        }
        ll z=tmp;
    //    cout<<tmp+p<<endl;
        vector<ll> d(n);
        for(int j=0;j<n;j++){
          ll tmp2=0;
          ll z=i;
          for(int k=0;k<n;k++){
            if(z%2==0){
              tmp2+=dp[k][j];
            }
            z/=2;
          }
          d[j]=tmp2;
        }
        sor(d);
        for(int j=0;j<e;j++){
          tmp+=d[j];
        }
       chmin(ans,tmp+p);
      }
    }
  }
  cout<<ans<<endl;
}
0