結果
問題 | No.2267 群の公理 |
ユーザー |
|
提出日時 | 2023-04-14 21:48:32 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,739 bytes |
コンパイル時間 | 11,434 ms |
コンパイル使用メモリ | 281,312 KB |
最終ジャッジ日時 | 2025-02-12 06:33:20 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#line 2 "/home/cocojapanpan/Procon_CPP/proconLibrary/lib/template/procon.hpp"#ifndef DEBUG// 提出時にassertはオフ#ifndef NDEBUG#define NDEBUG#endif// 定数倍高速化#pragma GCC target("avx2")#pragma GCC optimize("O3")#pragma GCC optimize("unroll-loops")#endif#include <bits/stdc++.h>using namespace std;using ll = long long;#define ALL(x) (x).begin(), (x).end()template <class T>using vec = vector<T>;template <class T, class S>inline bool chmax(T &a, const S &b) {return (a < b ? a = b, 1 : 0);}template <class T, class S>inline bool chmin(T &a, const S &b) {return (a > b ? a = b, 1 : 0);}template <class T>constexpr T INF = 1'000'000'000;template <>constexpr int INF<int> = 1'000'000'000;template <>constexpr ll INF<ll> = ll(INF<int>) * INF<int> * 2;#line 2 "main.cpp"int N;// 結合律の確認bool associative(const vec<vec<int>> &group) {for(int a = 0; a < N; a++) {for(int b = 0; b < N; b++) {for(int c = 0; c < N; c++) {// (a x b) x cint formerComp = group[group[a][b]][c];// a x (b x c)int latterComp = group[a][group[b][c]];if(formerComp != latterComp) return false;}}}return true;}// 単位元を返すvec<int> getUnit(const vec<vec<int>> &group) {// 単位元の候補達vec<bool> unitCandidate(N, true);for(int a = 0; a < N; a++) {for(int e = 0; e < N; e++) {// a x e = a かつ e x a = aif(group[a][e] == a && group[e][a] == a) continue;unitCandidate[e] = false;}}vec<int> ret;for(int e = 0; e < N; e++) {if(unitCandidate[e]) ret.push_back(e);}return ret;}// 単位元eについて、逆元が存在するかbool haveInverse(const vec<vec<int>> &group, int e) {for(int a = 0; a < N; a++) {bool ok = false;for(int i = 0; i < N; i++) {// a x i = i x a = e なるiが存在if(group[a][i] == e && group[i][a] == e) {ok = true;break;}}if(!ok) return false;}return true;}bool solve(const vec<vec<int>> &group) {if(!associative(group)) return false;vec<int> units = getUnit(group);for(int e : units) {if(haveInverse(group, e)) return true;}return false;}int main() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cin >> N;vec<vec<int>> group(N, vec<int>(N));for(int i = 0; i < N; i++) {for(int j = 0; j < N; j++) {cin >> group[i][j];}}cout << (solve(group) ? "Yes" : "No") << "\n";}