結果

問題 No.2267 群の公理
ユーザー lightlight
提出日時 2023-05-14 16:20:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,509 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 203,940 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 04:35:23
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,384 KB
testcase_47 AC 1 ms
4,384 KB
testcase_48 AC 1 ms
4,384 KB
testcase_49 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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