結果

問題 No.1345 Beautiful BINGO
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2021-01-16 15:09:00
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,141 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 141,712 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-05 17:48:17
合計ジャッジ時間 5,472 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 WA -
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 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by zeronosu77108 on Jan 15, 2021.
//
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <complex>
#include <optional>
#include <climits>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<(v)<<endl;}

int main() {
    int n, m;
    cin >> n >> m;

    vector a(n, vector(n, 0));
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) cin >> a[i][j];
    }

    vector row(n, 0);
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            row[i] += a[i][j];
        }
    }

    vector col(n, vector(1<<n, 0));
    for (int i=0; i<1<<n; i++) {
        for (int j=0; j<n; j++) {
            for (int k=0; k<n; k++) {
                if ((i>>k&1)==0) col[j][i] += a[k][j];
            }
        }
    }

    long comb = (1L<<m) - 1;
    long ans = LONG_MAX;
    while (comb < 1L << (2*n+1)) {
        long x=comb&-comb, y=comb+x;
        comb = ((comb & ~y) / x >> 1) | y;

        long d = comb & 3;
        long r = ((comb)>>2) & ((1<<n)-1);
        long c = ((comb)>>(n+2));


        long sum = 0;
        for (int i=0; i<n; i++) {
            if (r>>i&1) {
                sum += row[i];
            }
        }

        for (int i=0; i<n; i++) {
            if (c>>i&1) {
                sum += col[i][r];
            }
        }

        if (d&1) {
            for (int i=0; i<n; i++) {
                if (r>>i&1 || c>>i&1) continue;
                sum += a[i][i];
            }
        }

        if (d&2) {
            for (int i=0; i<n; i++) {
                if (r>>i&1 || c>>(n-i-1)&1) continue;
                sum += a[i][n-i-1];
            }
        }

        ans = min(ans, sum);
    }

    cout << ans << endl;
}
0