結果

問題 No.1345 Beautiful BINGO
ユーザー KudeKude
提出日時 2021-01-16 16:52:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 1,973 ms
コンパイル使用メモリ 203,920 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 07:16:10
合計ジャッジ時間 7,588 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 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 11 ms
5,376 KB
testcase_23 AC 236 ms
5,376 KB
testcase_24 AC 105 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 49 ms
5,376 KB
testcase_27 AC 227 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 49 ms
5,376 KB
testcase_30 AC 23 ms
5,376 KB
testcase_31 AC 12 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 234 ms
5,376 KB
testcase_34 AC 4 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 225 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 48 ms
5,376 KB
testcase_39 AC 227 ms
5,376 KB
testcase_40 AC 107 ms
5,376 KB
testcase_41 AC 104 ms
5,376 KB
testcase_42 AC 2 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 228 ms
5,376 KB
testcase_53 AC 233 ms
5,376 KB
testcase_54 AC 237 ms
5,376 KB
testcase_55 AC 226 ms
5,376 KB
testcase_56 AC 223 ms
5,376 KB
testcase_57 AC 230 ms
5,376 KB
testcase_58 AC 232 ms
5,376 KB
testcase_59 AC 225 ms
5,376 KB
testcase_60 AC 229 ms
5,376 KB
testcase_61 AC 232 ms
5,376 KB
testcase_62 AC 233 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

short a[16][16];
short cs[16];
bool use[16][16];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    rep(i, n) rep(j, n) cin >> a[i][j];
    short ans = 30000;
    rep(s, 1 << n + 2) {
        rep(i, n) rep(j, n) use[i][j] = false;
        rep(i, n) if (s >> i & 1) rep(j, n) use[i][j] = true;
        if (s >> n & 1) rep(i, n) use[i][i] = true;
        if (s >> n + 1 & 1) rep(i, n) use[n-1-i][i] = true;
        short score = 0;
        rep(i, n) rep(j, n) score += use[i][j] * a[i][j];
        rep(i, n) cs[i] = 0;
        rep(i, n) rep(j, n) if (!use[i][j]) cs[j] += a[i][j];
        sort(cs, cs + n);
        int idx = 0;
        short cnt = __builtin_popcount(s);
        while(cnt < m && idx < n) score += cs[idx++], cnt++;
        if (cnt == m) chmin(ans, score);
    }
    cout << ans << endl;
}
0