結果

問題 No.452 横着者のビンゴゲーム
ユーザー どららどらら
提出日時 2016-12-03 22:17:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 276 ms / 3,000 ms
コード長 1,976 bytes
コンパイル時間 3,252 ms
コンパイル使用メモリ 92,556 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-19 08:54:04
合計ジャッジ時間 4,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 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,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 49 ms
4,376 KB
testcase_15 AC 47 ms
4,380 KB
testcase_16 AC 28 ms
4,380 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 28 ms
4,380 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 13 ms
4,376 KB
testcase_21 AC 65 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 117 ms
4,376 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 73 ms
4,376 KB
testcase_27 AC 48 ms
4,376 KB
testcase_28 AC 32 ms
4,380 KB
testcase_29 AC 19 ms
4,380 KB
testcase_30 AC 84 ms
4,380 KB
testcase_31 AC 16 ms
4,376 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 41 ms
4,384 KB
testcase_34 AC 32 ms
4,376 KB
testcase_35 AC 25 ms
4,376 KB
testcase_36 AC 7 ms
4,376 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 276 ms
4,380 KB
testcase_39 AC 189 ms
4,380 KB
testcase_40 AC 188 ms
4,380 KB
testcase_41 AC 192 ms
4,380 KB
testcase_42 AC 190 ms
4,384 KB
testcase_43 AC 199 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

struct ST {
  int m;
  vector<int> v;
  ST(int n):v(n,0){}
};

ll c;

ll calc(const ST& a, const ST& b){
  ll ret = 0;
  int N = a.v.size();
  int i=0, j=0;
  while(i<N && j<N){
    if(ret + max(N-i, N-j) < c) return -1;
    if(a.v[i] == b.v[j]){
      ret++;
      i++;
      j++;
    }
    else if(a.v[i] < b.v[j]){
      i++;
    }
    else if(a.v[i] > b.v[j]){
      j++;
    }
  }
  
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  
  int N, M;
  cin >> N >> M;
  vector< vector<ST> > w;
  
  rep(i,M){
    vector<ST> v;
    vector< vector<int> > card(N, vector<int>(N, 0));
    rep(j,N){
      rep(k,N){
        cin >> card[j][k];
      }
    }

    rep(j,N){
      ST st(N);
      st.m = i;
      rep(k,N) st.v[k] = card[j][k];
      sort(ALLOF(st.v));
      v.push_back(st);
    }
    rep(k,N){
      ST st(N);
      st.m = i;
      rep(j,N) st.v[j] = card[j][k];
      sort(ALLOF(st.v));
      v.push_back(st);
    }
    {
      ST st1(N), st2(N);
      st1.m = i;
      st2.m = i;
      rep(j,N){
        st1.v[j] = card[j][j];
        st2.v[j] = card[j][N-1-j];
      }
      sort(ALLOF(st1.v));
      sort(ALLOF(st2.v));
      v.push_back(st1);
      v.push_back(st2);
    }
    w.push_back(v);
  }

  c = 0;
  rep(i,w.size()){
    rep(ii,w[i].size()){
      REP(j,i+1,w.size()){
        rep(jj,w[j].size()){
          c = max(c, calc(w[i][ii], w[j][jj]));
        }
      }
    }
  }

  cout << 2LL*N - c - 1 << endl;
    
  return 0;
}

0