結果

問題 No.452 横着者のビンゴゲーム
ユーザー simansiman
提出日時 2023-07-02 01:22:44
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 3,000 ms
コード長 1,910 bytes
コンパイル時間 2,959 ms
コンパイル使用メモリ 108,752 KB
実行使用メモリ 10,296 KB
最終ジャッジ日時 2023-09-22 20:19:03
合計ジャッジ時間 4,825 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,692 KB
testcase_01 AC 2 ms
4,656 KB
testcase_02 AC 2 ms
4,728 KB
testcase_03 AC 3 ms
4,872 KB
testcase_04 AC 2 ms
4,764 KB
testcase_05 AC 3 ms
4,916 KB
testcase_06 AC 3 ms
4,628 KB
testcase_07 AC 3 ms
4,684 KB
testcase_08 AC 3 ms
4,784 KB
testcase_09 AC 3 ms
4,692 KB
testcase_10 AC 3 ms
4,672 KB
testcase_11 AC 3 ms
4,784 KB
testcase_12 AC 2 ms
4,620 KB
testcase_13 AC 2 ms
4,640 KB
testcase_14 AC 19 ms
6,448 KB
testcase_15 AC 18 ms
6,428 KB
testcase_16 AC 10 ms
5,624 KB
testcase_17 AC 3 ms
4,740 KB
testcase_18 AC 9 ms
5,812 KB
testcase_19 AC 6 ms
5,324 KB
testcase_20 AC 5 ms
5,232 KB
testcase_21 AC 18 ms
6,840 KB
testcase_22 AC 5 ms
5,168 KB
testcase_23 AC 27 ms
7,892 KB
testcase_24 AC 5 ms
5,120 KB
testcase_25 AC 4 ms
5,032 KB
testcase_26 AC 17 ms
6,696 KB
testcase_27 AC 10 ms
5,876 KB
testcase_28 AC 10 ms
5,880 KB
testcase_29 AC 7 ms
5,400 KB
testcase_30 AC 20 ms
7,268 KB
testcase_31 AC 5 ms
5,252 KB
testcase_32 AC 4 ms
5,056 KB
testcase_33 AC 8 ms
5,668 KB
testcase_34 AC 9 ms
5,748 KB
testcase_35 AC 6 ms
5,440 KB
testcase_36 AC 4 ms
5,108 KB
testcase_37 AC 4 ms
5,004 KB
testcase_38 AC 53 ms
10,296 KB
testcase_39 AC 34 ms
8,716 KB
testcase_40 AC 33 ms
8,764 KB
testcase_41 AC 34 ms
8,600 KB
testcase_42 AC 34 ms
8,636 KB
testcase_43 AC 33 ms
8,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  int C[M][N][N];

  for (int i = 0; i < M; ++i) {
    for (int y = 0; y < N; ++y) {
      for (int x = 0; x < N; ++x) {
        cin >> C[i][y][x];
      }
    }
  }

  vector<vector<int>> lines[M];

  for (int i = 0; i < M; ++i) {
    for (int y = 0; y < N; ++y) {
      vector<int> line;

      for (int x = 0; x < N; ++x) {
        line.push_back(C[i][y][x]);
      }

      lines[i].push_back(line);
    }

    for (int x = 0; x < N; ++x) {
      vector<int> line;

      for (int y = 0; y < N; ++y) {
        line.push_back(C[i][y][x]);
      }

      lines[i].push_back(line);
    }

    {
      vector<int> line;

      for (int j = 0; j < N; ++j) {
        line.push_back(C[i][j][j]);
      }

      lines[i].push_back(line);
    }

    {
      vector<int> line;

      for (int j = 0; j < N; ++j) {
        line.push_back(C[i][j][N - j - 1]);
      }

      lines[i].push_back(line);
    }
  }

  vector<int> ids[50000];
  int LS = 2 * N + 2;

  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < lines[i].size(); ++j) {
      int id = i * LS + j;

      for (int v : lines[i][j]) {
        ids[v].push_back(id);
      }
    }
  }

  int ans = 2 * N - 1;
  map<int, map<int, int>> counter;

  for (int v = 0; v <= N * N * M; ++v) {
    int len = ids[v].size();

    for (int i = 0; i < len; ++i) {
      int id1 = ids[v][i];

      for (int j = i + 1; j < len; ++j) {
        int id2 = ids[v][j];
        if (id1 / LS == id2 / LS) continue;

        counter[id1][id2]++;
        counter[id2][id1]++;
        ans = min(ans, 2 * N - 1 - counter[id1][id2]);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0