結果

問題 No.452 横着者のビンゴゲーム
ユーザー rickythetarickytheta
提出日時 2016-12-03 00:35:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 543 ms / 3,000 ms
コード長 2,336 bytes
コンパイル時間 3,437 ms
コンパイル使用メモリ 165,544 KB
実行使用メモリ 4,440 KB
最終ジャッジ日時 2023-08-19 06:57:22
合計ジャッジ時間 9,308 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 103 ms
4,440 KB
testcase_15 AC 101 ms
4,400 KB
testcase_16 AC 67 ms
4,376 KB
testcase_17 AC 39 ms
4,380 KB
testcase_18 AC 58 ms
4,376 KB
testcase_19 AC 44 ms
4,376 KB
testcase_20 AC 38 ms
4,376 KB
testcase_21 AC 131 ms
4,380 KB
testcase_22 AC 39 ms
4,380 KB
testcase_23 AC 231 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 17 ms
4,380 KB
testcase_26 AC 148 ms
4,380 KB
testcase_27 AC 109 ms
4,376 KB
testcase_28 AC 65 ms
4,376 KB
testcase_29 AC 44 ms
4,376 KB
testcase_30 AC 171 ms
4,380 KB
testcase_31 AC 30 ms
4,380 KB
testcase_32 AC 24 ms
4,380 KB
testcase_33 AC 81 ms
4,376 KB
testcase_34 AC 68 ms
4,380 KB
testcase_35 AC 58 ms
4,376 KB
testcase_36 AC 21 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 543 ms
4,380 KB
testcase_39 AC 378 ms
4,380 KB
testcase_40 AC 380 ms
4,376 KB
testcase_41 AC 378 ms
4,380 KB
testcase_42 AC 378 ms
4,376 KB
testcase_43 AC 383 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
vector< vector<vi> > C;

int main(){
  scanf("%d%d",&n,&m);
  C.resize(m);
  REP(i,m){
    C[i].resize(n);
    REP(j,n){
      C[i][j].resize(n);
      REP(k,n)scanf("%d",&C[i][j][k]);
    }
  }
  vector< vector<vi> > U;
  U.resize(m);
  REP(i,m){
    // tate,yoko
    REP(j,n){
      vi x;
      vi y;
      REP(k,n){
        x.push_back(C[i][j][k]);
        y.push_back(C[i][k][j]);
      }
      sort(ALL(x));
      sort(ALL(y));
      U[i].push_back(x);
      U[i].push_back(y);
    }
    // naname
    {
      vi x;
      vi y;
      REP(k,n){
        x.push_back(C[i][k][k]);
        y.push_back(C[i][k][n-1-k]);
      }
      sort(ALL(x));
      sort(ALL(y));
      U[i].push_back(x);
      U[i].push_back(y);
    }
  }
  // all check
  {
    set<vi> S;
    REP(i,m){
      for(vi V:U[i]){
        if(S.count(V)){
          printf("%d\n",n-1);
          return 0;
        }
      }
      for(vi V:U[i]){
        S.insert(V);
      }
    }
  }
  // partial check
  int ans = 252521;
  REP(i,m){
    for(vi V:U[i]){
      REP(j,m){
        if(i==j)continue;
        for(vi W:U[j]){
          // same count
          int same = 0;
          int x=0, y=0;
          while(x<n && y<n){
            if(V[x]==W[y]){
              same++;
              x++;
              y++;
            }else if(V[x]<W[y]){
              x++;
            }else{
              y++;
            }
          }
          CHMIN(ans,n+(n-same-1));
        }
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}
0