結果

問題 No.452 横着者のビンゴゲーム
ユーザー hanorverhanorver
提出日時 2016-12-03 01:41:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,260 ms / 3,000 ms
コード長 2,085 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 88,876 KB
実行使用メモリ 7,380 KB
最終ジャッジ日時 2023-08-19 07:01:43
合計ジャッジ時間 10,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 444 ms
7,260 KB
testcase_15 AC 432 ms
7,380 KB
testcase_16 AC 225 ms
5,340 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 AC 94 ms
4,380 KB
testcase_19 AC 49 ms
4,380 KB
testcase_20 AC 33 ms
4,380 KB
testcase_21 AC 251 ms
4,568 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 482 ms
5,180 KB
testcase_24 AC 19 ms
4,380 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 261 ms
4,380 KB
testcase_27 AC 131 ms
4,380 KB
testcase_28 AC 110 ms
4,376 KB
testcase_29 AC 50 ms
4,376 KB
testcase_30 AC 326 ms
4,668 KB
testcase_31 AC 39 ms
4,376 KB
testcase_32 AC 21 ms
4,380 KB
testcase_33 AC 95 ms
4,380 KB
testcase_34 AC 97 ms
4,384 KB
testcase_35 AC 58 ms
4,384 KB
testcase_36 AC 13 ms
4,376 KB
testcase_37 AC 14 ms
4,380 KB
testcase_38 AC 1,260 ms
6,496 KB
testcase_39 AC 744 ms
5,336 KB
testcase_40 AC 747 ms
5,336 KB
testcase_41 AC 748 ms
5,336 KB
testcase_42 AC 746 ms
5,632 KB
testcase_43 AC 752 ms
5,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    // 基本的には辺の長さで良い
    // しかし、そのときにビンゴになるのが2つ以上あれば辺の長さ-1
    int n, m;

    std::cin >> n >> m;

    std::vector<std::vector<int> > bingo(n, std::vector<int>(n));
    // i人目のj個目のビンゴのになる数値の要素
    std::vector<std::vector<std::set<int> > > v(m);

    for (int k = 0; k < m; k++) {
        std::set<int> s;
        for (int i = 0; i < n * n; i++) {
            if (i != 0 && i % n == 0) {
                v[k].push_back(s);
                s.clear();
            }
            std::cin >> bingo[i / n][i % n];
            s.insert(bingo[i / n][i % n]);

        }
        v[k].push_back(s);
        // 縦のビンゴを見る
        for (int i = 0; i < n; i++) {
            s.clear();
            for (int j = 0; j < n; j++) {
                s.insert(bingo[j][i]);
            }
            v[k].push_back(s);
        }
        v[k].push_back(s);
        s.clear();
        // 斜めのビンゴ
        for (int i = 0; i < n; i++) {
            s.insert(bingo[i][i]);
        }
        v[k].push_back(s);
        s.clear();
        for (int i = 0; i < n; i++) {
            s.insert(bingo[i][n - i - 1]);
        }
        v[k].push_back(s);
    }
    // 一致率を求める
    int max_match = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < v[i].size(); j++) {
            for (int k = i + 1; k < m; k++) {
                for (int l = 0; l < v[k].size(); l++) {
                    int n_match = 0;
                    for (auto it = v[i][j].begin(); it != v[i][j].end(); it++) {
                        if (v[k][l].find(*it) != v[k][l].end()) {
                            n_match++;
                        }
                    }
                    max_match = std::max(max_match, n_match);
                }
            }
        }
    }
    int ans = std::max(n + (n - (max_match + 1)), n - 1);

    std::cout << ans << std::endl;

    return 0;
}
0