結果

問題 No.452 横着者のビンゴゲーム
ユーザー koyoprokoyopro
提出日時 2020-01-04 22:35:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,644 ms / 3,000 ms
コード長 1,936 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 156,264 KB
実行使用メモリ 38,476 KB
最終ジャッジ日時 2023-08-14 20:49:45
合計ジャッジ時間 15,888 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 857 ms
7,660 KB
testcase_15 AC 822 ms
7,644 KB
testcase_16 AC 488 ms
5,668 KB
testcase_17 AC 56 ms
38,476 KB
testcase_18 AC 158 ms
4,380 KB
testcase_19 AC 91 ms
5,008 KB
testcase_20 AC 62 ms
4,948 KB
testcase_21 AC 381 ms
4,664 KB
testcase_22 AC 48 ms
4,948 KB
testcase_23 AC 686 ms
5,396 KB
testcase_24 AC 41 ms
5,132 KB
testcase_25 AC 22 ms
4,948 KB
testcase_26 AC 416 ms
4,640 KB
testcase_27 AC 271 ms
5,012 KB
testcase_28 AC 178 ms
4,508 KB
testcase_29 AC 102 ms
5,012 KB
testcase_30 AC 494 ms
4,876 KB
testcase_31 AC 71 ms
5,008 KB
testcase_32 AC 42 ms
5,008 KB
testcase_33 AC 192 ms
5,016 KB
testcase_34 AC 172 ms
5,012 KB
testcase_35 AC 111 ms
5,200 KB
testcase_36 AC 28 ms
5,012 KB
testcase_37 AC 32 ms
4,944 KB
testcase_38 AC 1,644 ms
6,984 KB
testcase_39 AC 1,110 ms
5,684 KB
testcase_40 AC 1,104 ms
5,704 KB
testcase_41 AC 1,106 ms
5,852 KB
testcase_42 AC 1,107 ms
5,656 KB
testcase_43 AC 1,109 ms
5,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

/*================================*/

int N,M,L;
int C[222][222][222];

void set_line(set<int> *line, int m, int l) {
    line->clear();
    if (l<N) {
        // 横
        REP(i,N) line->insert(C[m][l][i]);
    }
    else if (l<2*N) {
        // 縦
        REP(i,N) line->insert(C[m][i][l-N]);
    }
    else if (l==2*N) {
        // 斜め
        REP(i,N) line->insert(C[m][i][i]);
    }
    else {
        // 斜め(逆)
        REP(i,N) line->insert(C[m][i][N-1-i]);
    }
}

vector<set<int>> S[222];

signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin>>N>>M;
    
    REP(m,M) {
        REP(i,N)REP(j,N)cin>>C[m][i][j];
        REP(l,2*N+2) {
            set<int> line;
            set_line(&line, m, l);
            S[m].push_back(line);
        }
    }
    int ma = 0; // 最大マッチ数
    REP(m,M-1) {
        for (auto l : S[m]) {
            FOR(o,m+1,M) {
                for (auto r : S[o]) {
                    set<int> result;
                    set_intersection(l.begin(), l.end(),
                                     r.begin(), r.end(),
                                     std::inserter(result, result.end()));
                    ma = max(ma, (int)result.size());
                }
            }
        }
    }
    
    cout << 2*N-1-ma << endl;
    
    return 0;
}
0