結果

問題 No.1345 Beautiful BINGO
ユーザー maguromaguro
提出日時 2021-01-12 16:34:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,430 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 211,052 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2023-08-15 20:50:44
合計ジャッジ時間 6,836 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,808 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 8 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 187 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 187 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
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 #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

template<class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> bingo(N,vector<int>(N));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            cin >> bingo.at(i).at(j);
        }
    }
    int ret = Inf;
    for(int bit = 0;bit < (1 << (2 * N + 2));bit++) {
        vector<int> cnt;
        for(int i = 0;i < (2 * N + 2);i++) {
            if(bit & (1 << i)) {
                cnt.push_back(i);
            }
        }
        if(cnt.size() < M) continue;
        vector<vector<bool>> isopened(N,vector<bool>(N));
        for(int i = 0;i < cnt.size();i++) {
            if(cnt.at(i) < N) {
                for(int j = 0;j < N;j++) {
                    isopened.at(cnt.at(i)).at(j) = true;
                }
            } 
            else if(cnt.at(i) < 2 * N) {
                for(int j = 0;j < N;j++) {
                    isopened.at(j).at(cnt.at(i) - N) = true;
                }
            }
            else if(cnt.at(i) == 2 * N) {
                for(int j = 0;j < N;j++) {
                    isopened.at(j).at(j) = true;
                }
            }
            else {
                for(int j = 0;j < N;j++) {
                    isopened.at(j).at(N - 1 - j) = true;
                }
            }
        }
        int res = 0;
        for(int i = 0;i < N;i++) {
            for(int j = 0;j < N;j++) {
                if(isopened.at(i).at(j)) res += bingo.at(i).at(j);
            }
        }
        chmin(ret,res);
    }
    cout << ret << endl;
}
0