結果

問題 No.452 横着者のビンゴゲーム
ユーザー tnakao0123tnakao0123
提出日時 2016-12-05 09:48:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 576 ms / 3,000 ms
コード長 1,808 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 87,552 KB
実行使用メモリ 15,984 KB
最終ジャッジ日時 2023-08-19 09:05:26
合計ジャッジ時間 6,665 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 248 ms
4,384 KB
testcase_15 AC 241 ms
4,380 KB
testcase_16 AC 132 ms
4,384 KB
testcase_17 AC 10 ms
15,984 KB
testcase_18 AC 40 ms
4,380 KB
testcase_19 AC 27 ms
5,840 KB
testcase_20 AC 19 ms
9,936 KB
testcase_21 AC 109 ms
4,384 KB
testcase_22 AC 16 ms
11,760 KB
testcase_23 AC 224 ms
4,384 KB
testcase_24 AC 12 ms
15,916 KB
testcase_25 AC 8 ms
7,900 KB
testcase_26 AC 108 ms
4,384 KB
testcase_27 AC 67 ms
5,864 KB
testcase_28 AC 45 ms
4,380 KB
testcase_29 AC 27 ms
5,872 KB
testcase_30 AC 139 ms
4,380 KB
testcase_31 AC 19 ms
4,380 KB
testcase_32 AC 13 ms
5,732 KB
testcase_33 AC 49 ms
5,952 KB
testcase_34 AC 45 ms
4,380 KB
testcase_35 AC 34 ms
7,760 KB
testcase_36 AC 10 ms
9,992 KB
testcase_37 AC 10 ms
13,836 KB
testcase_38 AC 576 ms
4,384 KB
testcase_39 AC 334 ms
4,384 KB
testcase_40 AC 334 ms
4,384 KB
testcase_41 AC 333 ms
4,384 KB
testcase_42 AC 334 ms
4,380 KB
testcase_43 AC 334 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 452.cc: No.452 横着者のビンゴゲーム - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_K = MAX_N * 2 + 2;
const int MAX_M = 200;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int cs[MAX_N][MAX_N];
int bs[MAX_M][MAX_K][MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  cin >> n >> m;
  int l = n * 2 + 2;

  for (int i = 0; i < m; i++) {
    for (int y = 0; y < n; y++)
      for (int x = 0; x < n; x++) cin >> cs[y][x];
    int j = 0;
    for (int y = 0; y < n; y++, j++)
      for (int x = 0; x < n; x++) bs[i][j][x] = cs[y][x];
    for (int x = 0; x < n; x++, j++)
      for (int y = 0; y < n; y++) bs[i][j][y] = cs[y][x];
    for (int y = 0; y < n; y++) bs[i][j][y] = cs[y][y];
    j++;
    for (int y = 0; y < n; y++) bs[i][j][y] = cs[y][n - 1 - y];

    for (int j = 0; j < l; j++) sort(bs[i][j], bs[i][j] + n);
  }

  int maxc = 0;
  for (int i0 = 0; i0 < m; i0++)
    for (int i1 = i0 + 1; i1 < m; i1++)
      for (int j0 = 0; j0 < l; j0++)
	for (int j1 = 0; j1 < l; j1++) {
	  int c = 0;
	  for (int k0 = 0; k0 < n; k0++) {
	    int k1 =
	      lower_bound(bs[i1][j1], bs[i1][j1] + n, bs[i0][j0][k0])
	      - bs[i1][j1];
	    if (k1 < n && bs[i1][j1][k1] == bs[i0][j0][k0]) c++;
	  }
	  if (maxc < c) maxc = c;
	}

  //printf("maxc=%d\n", maxc);
  printf("%d\n", n * 2 - maxc - 1);
  return 0;
}
0