結果

問題 No.452 横着者のビンゴゲーム
ユーザー ytftytft
提出日時 2021-04-01 16:17:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,776 ms / 3,000 ms
コード長 1,379 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 180,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 19:03:54
合計ジャッジ時間 19,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1,445 ms
4,376 KB
testcase_15 AC 1,382 ms
4,376 KB
testcase_16 AC 790 ms
4,380 KB
testcase_17 AC 66 ms
4,376 KB
testcase_18 AC 163 ms
4,376 KB
testcase_19 AC 105 ms
4,380 KB
testcase_20 AC 79 ms
4,380 KB
testcase_21 AC 398 ms
4,380 KB
testcase_22 AC 66 ms
4,380 KB
testcase_23 AC 733 ms
4,380 KB
testcase_24 AC 49 ms
4,380 KB
testcase_25 AC 29 ms
4,380 KB
testcase_26 AC 434 ms
4,376 KB
testcase_27 AC 296 ms
4,376 KB
testcase_28 AC 184 ms
4,380 KB
testcase_29 AC 112 ms
4,380 KB
testcase_30 AC 513 ms
4,376 KB
testcase_31 AC 79 ms
4,376 KB
testcase_32 AC 51 ms
4,380 KB
testcase_33 AC 215 ms
4,376 KB
testcase_34 AC 189 ms
4,376 KB
testcase_35 AC 138 ms
4,380 KB
testcase_36 AC 37 ms
4,376 KB
testcase_37 AC 37 ms
4,376 KB
testcase_38 AC 1,776 ms
4,380 KB
testcase_39 AC 1,159 ms
4,376 KB
testcase_40 AC 1,164 ms
4,376 KB
testcase_41 AC 1,161 ms
4,376 KB
testcase_42 AC 1,159 ms
4,376 KB
testcase_43 AC 1,159 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int calc(vector<vector<int>>& A,vector<vector<int>>& B,int N,int M){
    vector<vector<int>> a(2*N+2,vector<int>(N)),b(2*N+2,vector<int>(N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            a[i][j]=A[i][j];
            b[i][j]=B[i][j];
            a[i+N][j]=A[j][i];
            b[i+N][j]=B[j][i];
        }
    } 
    for(int i=0;i<N;i++){
        a[2*N][i]=A[i][i];
        a[2*N+1][i]=A[i][N-1-i];
        b[2*N][i]=B[i][i];
        b[2*N+1][i]=B[i][N-1-i];
    }
    int ret=2*N-1;
    int temp;
    map<int,int> m;
    for(int i=0;i<2*N+2;i++){
        for(int j=0;j<2*N+2;j++){
            temp=2*N-1;
            m.clear();
            for(int k=0;k<N;k++){
                m[a[i][k]]=1;
            }
            for(int k=0;k<N;k++){
                temp-=m.count(b[j][k]);
            }
            ret=min(ret,temp);
        }
    }
    return ret;
}

int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<vector<int>>> cards(M,vector<vector<int>>(N,vector<int>(N)));
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                cin>>cards[i][j][k];
            }
        }
    }
    int ans=INT_MAX;
    for(int i=0;i<M-1;i++){
        for(int j=i+1;j<M;j++){
            ans=min(ans,calc(cards[i],cards[j],N,M));
        }
    }
    cout<<ans<<endl;
}
0