結果

問題 No.452 横着者のビンゴゲーム
ユーザー ckawatakckawatak
提出日時 2019-01-02 18:10:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 346 ms / 3,000 ms
コード長 1,889 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 79,416 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 05:59:28
合計ジャッジ時間 6,242 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 136 ms
6,940 KB
testcase_15 AC 132 ms
6,944 KB
testcase_16 AC 110 ms
6,940 KB
testcase_17 AC 67 ms
6,944 KB
testcase_18 AC 49 ms
6,944 KB
testcase_19 AC 56 ms
6,944 KB
testcase_20 AC 56 ms
6,944 KB
testcase_21 AC 97 ms
6,944 KB
testcase_22 AC 59 ms
6,940 KB
testcase_23 AC 154 ms
6,940 KB
testcase_24 AC 51 ms
6,940 KB
testcase_25 AC 27 ms
6,940 KB
testcase_26 AC 114 ms
6,944 KB
testcase_27 AC 117 ms
6,940 KB
testcase_28 AC 54 ms
6,940 KB
testcase_29 AC 55 ms
6,944 KB
testcase_30 AC 126 ms
6,944 KB
testcase_31 AC 33 ms
6,940 KB
testcase_32 AC 36 ms
6,940 KB
testcase_33 AC 91 ms
6,940 KB
testcase_34 AC 65 ms
6,940 KB
testcase_35 AC 82 ms
6,940 KB
testcase_36 AC 34 ms
6,944 KB
testcase_37 AC 38 ms
6,940 KB
testcase_38 AC 346 ms
6,944 KB
testcase_39 AC 261 ms
6,944 KB
testcase_40 AC 264 ms
6,940 KB
testcase_41 AC 265 ms
6,944 KB
testcase_42 AC 262 ms
6,944 KB
testcase_43 AC 261 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, M;

    cin >> N >> M;

    vector<vector<vector<int> > > players(M);

    for (int i = 0; i < M; i++) {
        vector<vector<int> > card(N);
        for (int j = 0; j < N; j++) {
            vector<int> row(N);
            for (int k = 0; k < N; k++) {
                cin >> row[k];
            }
            card[j] = row;
        }
        players[i] = card;
    }

    vector<vector<vector<int> > > bingos(M);
    
    for (int i = 0; i < M; i++) {
        // left to right
        for (int j = 0; j < N; j++) {
            vector<int> lr = players[i][j];
            bingos[i].push_back(lr); 
        }

        // top to down
        for (int j = 0; j < N; j++) {
            vector<int> td(N);
            for (int k = 0; k < N; k++) {
                td[k] = players[i][k][j];
            }
            bingos[i].push_back(td);
        }
        
        // upper left to lower right
        vector<int> ullr(N);
        for (int j = 0; j < N; j++) {
            ullr[j] = players[i][j][j];
        }
        bingos[i].push_back(ullr);

        // upper right to lower left
        vector<int> urll(N);
        for (int j = 0; j < N; j++) {
            urll[j] = players[i][j][N-j-1];
        }
        bingos[i].push_back(urll);

        for (auto& bingo : bingos[i]) {
            sort(bingo.begin(), bingo.end());
        }
    }

    int answer = 2*N;
    for (int i = 0; i < M; i++) {
        for (auto& x : bingos[i]) {
            for (int j = 0; j < i; j++) {
                for (auto& y : bingos[j]) {
                    vector<int> z;
                    set_union(x.begin(), x.end(), y.begin(), y.end(), back_inserter(z));
                    answer = min(answer, (int)z.size()-1);
                }
            }
        }
    }
    cout << answer << endl;
}
0