結果

問題 No.2267 群の公理
ユーザー eoeo
提出日時 2023-05-14 16:20:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,509 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 199,044 KB
最終ジャッジ日時 2025-02-13 00:31:34
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;


int main() {
  ll n;
  cin >> n;

  vector result(n, vector<ll>(n));
  for (ll i = 0; i < n; ++i) {
    for (ll j = 0; j < n; ++j) cin >> result[i][j];
  }

  // 結合律
  bool is_associative = true;
  for (ll i = 0; i < n; ++i) {
    for (ll j = 0; j < n; ++j) {
      for (ll k = 0; k < n; ++k) {
        // (i@j) @ k = i @ (j@k)
        if (result[result[i][j]][k] != result[i][result[j][k]]) {
          is_associative = false;
        }
      }
    }
  }
  if (not is_associative) {
    cout << "No" << endl;
    return 0;
  }

  // 単位律
  bool exist_unit = false;
  ll unit = -1;
  for (ll e = 0; e < n; e++) {
      bool e_is_unit = true;
      for (ll x = 0; x < n; x++) {
          if (result[e][x] != x or result[x][e] != x) {
            e_is_unit = false;
          }
      }

      if (e_is_unit) {
        exist_unit = true;
        unit = e;
      }
  }

  if (not exist_unit) {
    cout << "No" << endl;
    return 0;
  }

  // cout << unit << endl;

  // 逆元
  // 任意の i に対して <-> すべての i に対して,
  for (ll i = 0; i < n; ++i) {
    // i @ j = e and j @ i = e を満たす j が存在する.
    bool exist_inverse = false;
    for (ll j = 0; j < n; ++j) {
      if (result[i][j] == unit and result[j][i] == unit) {
        exist_inverse = true;
      }
    }

    if (not exist_inverse) {
      cout << "No" << endl;
      exit(0);
    }
  }

  cout << "Yes" << endl;

  return 0;
}
0