結果

問題 No.1345 Beautiful BINGO
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2021-01-16 14:25:20
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,182 bytes
コンパイル時間 2,972 ms
コンパイル使用メモリ 141,708 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-05 16:44:13
合計ジャッジ時間 9,319 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 37 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 36 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
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 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 10 ms
5,376 KB
testcase_25 TLE -
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];
    }

    long comb = (1L<<m) - 1;
    long ans = LONG_MAX;
    while (comb < 1L << (2*n+2)) {
        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;
        vector used(n, vector(n, false));
        if (d & 1) {
            for (int i=0; i<n; i++) {
                if (used[i][i]) continue;
                used[i][i] = true;
                sum += a[i][i];
            }
        }

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

        for (int i=0; i<n; i++) {
            if (r>>i&1) {
                for (int j=0; j<n; j++) {
                    if (used[i][j]) continue;
                    used[i][j] = true;
                    sum += a[i][j];
                }
            }
        }


        for (int i=0; i<n; i++) {
            if (c>>i&1) {
                for (int j=0; j<n; j++) {
                    if (used[j][i]) continue;
                    used[j][i] = true;
                    sum += a[j][i];
                }
            }
        }
        ans = min(ans, sum);
    }

    cout << ans << endl;
}
0