結果

問題 No.1345 Beautiful BINGO
ユーザー kappybarkappybar
提出日時 2021-01-20 22:56:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 1,853 ms
コンパイル使用メモリ 173,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 02:32:13
合計ジャッジ時間 8,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 272 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 57 ms
4,376 KB
testcase_27 AC 261 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 59 ms
4,376 KB
testcase_30 AC 27 ms
4,380 KB
testcase_31 AC 14 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 265 ms
4,380 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 263 ms
4,380 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 56 ms
4,380 KB
testcase_39 AC 266 ms
4,376 KB
testcase_40 WA -
testcase_41 AC 125 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 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 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 266 ms
4,376 KB
testcase_53 AC 260 ms
4,376 KB
testcase_54 AC 272 ms
4,380 KB
testcase_55 AC 263 ms
4,380 KB
testcase_56 AC 258 ms
4,380 KB
testcase_57 AC 264 ms
4,376 KB
testcase_58 AC 266 ms
4,376 KB
testcase_59 AC 263 ms
4,376 KB
testcase_60 AC 259 ms
4,376 KB
testcase_61 AC 270 ms
4,376 KB
testcase_62 AC 263 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int a[20][20];

int main(){
    int n,m;
    cin >> n >> m;
    rep(i,n)rep(j,n) cin >> a[i][j];
    ll ans = LINF;
    rep(mask,4){
        ll res = 0;
        int t = 0;
        vector<vector<int>> maze(n,vector<int>(n,0));
        if(mask&1){
            ++t;
            rep(i,n){
                maze[i][i] = 1;
                res += a[i][i];
            }
        }
        if(mask>>1&1){
            ++t;
            rep(i,n){
                maze[i][n-i-1] = 1;
                res += a[i][n-i-1];
            }
        }
        for(int bit=0;bit<(1<<n);bit++){
            int pop = __builtin_popcount(bit) + t;
            ll ret = 0;
            rep(i,n){
                if(bit>>i&1){
                    rep(j,n){
                        if(maze[i][j]==0) ret += a[i][j];
                    }
                }
            }
            int num = m - pop;
            vector<int> b(n,0);
            rep(i,n){
                rep(j,n){
                    if(bit>>j&1) continue;
                    if(maze[j][i]==1) continue;
                    b[i] += a[j][i];
                }
            }
            sort(b.begin(),b.end());
            rep(i,num) ret += b[i];
            chmin(ans,res+ret);
        } 
    }
    cout << ans << endl;
    return 0;
}
0