結果

問題 No.452 横着者のビンゴゲーム
ユーザー ckawatakckawatak
提出日時 2019-01-02 16:40:29
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,337 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 74,828 KB
実行使用メモリ 168,480 KB
最終ジャッジ日時 2024-05-01 04:01:17
合計ジャッジ時間 6,358 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 7 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,948 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,944 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main() {
    int N, M;

    cin >> N >> M;

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

    int maximum = 0;
    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];
                maximum = max(maximum, row[k]);
            }
            card[j] = row;
        }
        players[i] = card;
    }

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

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

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

        bingos[i] = lines;
    }

    int min_unmatched = 100000000;
    for (int i = 0; i < M; i++) {
        for (int j = i+1; j < M; j++) {
            for (int x = 0; x < 2*N+2; x++) {
                for (int y = 0; y < 2*N+2; y++) {
                    int matched = 0;
                    for (int s = 0; s < maximum; s++) {
                        if (bingos[i][x][s] == 1 && bingos[j][y][s] == 1) {
                            matched++;
                        }
                    }
                    if (matched != 0) {
                        min_unmatched = min(min_unmatched, N-matched);
                    }
                }
            }
        }
    }
    min_unmatched = min(N,min_unmatched);

    cout << N+min_unmatched-1 << endl;
}
0