結果

問題 No.452 横着者のビンゴゲーム
ユーザー Hoi_koroHoi_koro
提出日時 2016-12-12 17:49:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 2,553 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 127,616 KB
実行使用メモリ 5,720 KB
最終ジャッジ日時 2023-08-19 21:08:46
合計ジャッジ時間 3,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 11 ms
5,664 KB
testcase_15 AC 11 ms
5,720 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 19 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 42 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 14 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 20 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 96 ms
5,228 KB
testcase_39 AC 39 ms
4,376 KB
testcase_40 AC 40 ms
4,376 KB
testcase_41 AC 40 ms
4,376 KB
testcase_42 AC 38 ms
4,380 KB
testcase_43 AC 39 ms
4,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define dump(a) cerr<<#a <<' '<< a <<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,ans=0;
    cin >> n >> m;
    vector<vector<PI>> id(n*n*m+1);
    vector<vector<vector<int>>> card(m,vector<vector<int>>(2*n+2));
    REP(i,m){
        int tmp;
        REP(j,n){
            REP(k,n){
                cin >> tmp;
                card[i][j].push_back(tmp);
                card[i][n+k].push_back(tmp);
                id[tmp].emplace_back(i,j);
                id[tmp].emplace_back(i,n+k);
                if(j==k){
                    card[i][2*n].push_back(tmp);
                    id[tmp].emplace_back(i,2*n);
                }
                if(j+k==n-1){
                    card[i][2*n+1].push_back(tmp);
                    id[tmp].emplace_back(i,2*n+1);
                }
                int loop=2+(j==k?1:0)+(j+k==n-1?1:0),size=id[tmp].size();
                for(int l=size-loop;l<size;++l){
                    for(int h=0;h<size-loop;++h){
                        int cnt=1;
                        for(int g=0;;g++){
                            int a=card[i][id[tmp][l].SE][g];
                            if(a==tmp)break;
                            vector<int> &v=card[id[tmp][h].FI][id[tmp][h].SE];
                            if(*lower_bound(ALL(v),a)==a)cnt++;
                        }
                        //if(ans<cnt) {dump(tmp)dump(loop)}
                        ans=max(ans,cnt);
                    }
                }
            }
        }
        REP(j,2*n+2)sort(ALL(card[i][j]));
    }

    cout << 2*n-1-ans <<endl;


    return 0;
}
0