結果
問題 | No.2267 群の公理 |
ユーザー | NAMIDAIRO |
提出日時 | 2023-04-14 21:39:05 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,195 bytes |
コンパイル時間 | 1,113 ms |
コンパイル使用メモリ | 122,432 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 12:21:29 |
合計ジャッジ時間 | 2,305 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <set> #include <random> #include <iomanip> #include <string> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) template<class T> using vi = vector<T>; template<class T> using vii = vector<vi<T>>; template<class T> using viii = vector<vii<T>>; using P = pair<ll, int>; void chmin(ll & x, ll y) { x = min(x, y); } int main() { int n; cin >> n; vii<int> a(n, vi<int>(n)); rep(i, n) rep(j, n) cin >> a[i][j]; bool ok = true; rep(i, n) rep(j, n) { if (a[i][j] != a[j][i]) ok = false; } //結合律 rep(i, n) rep(j, n) rep(k, n) { if (a[a[i][j]][k] != a[i][a[j][k]]) ok = false; } //単位律 vi<bool> check(n); rep(i, n){ bool t = true; rep(j, n) { if (a[i][j] == j && a[j][i] == j) continue; t = false; } check[i] = t; } //逆元律 bool ok2 = false; rep(i, n) { if (!check[i]) continue; int cnt = 0; rep(j, n) { rep(k, n) { if (a[j][k] == i) { cnt++; break; } } } if (cnt == n) ok2 = true; } if (ok && ok2) cout << "Yes" << endl; else cout << "No" << endl; return 0; }