結果

問題 No.2267 群の公理
ユーザー MarioYC
提出日時 2023-04-14 21:38:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 192,356 KB
最終ジャッジ日時 2025-02-12 06:25:46
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int N,T[30][30];

bool check(){
    for(int a = 0;a < N;++a){
        for(int b = 0;b < N;++b){
            for(int c = 0;c < N;++c){
                int ret1 = T[ T[a][b] ][c];
                int ret2 = T[a][ T[b][c] ];
                if(ret1 != ret2) return false;
            }
        }
    }
    bool found = false;
    for(int e = 0;e < N;++e){
        found = true;
        for(int i = 0;i < N;++i){
            if(T[i][e] != i || T[e][i] != i){
                found = false;
            }
        }
        if(!found) continue;
        for(int i = 0;i < N;++i){
            found = false;
            for(int j = 0;j < N;++j){
                if(T[i][j] == e && T[j][i] == e){
                    found = true;
                }
            }
            if(!found) break;
        }
        if(found){
            return true;
        }
    }
    return false;
}

int main(){
    cin >> N;
    for(int i = 0;i < N;++i){
        for(int j = 0;j < N;++j){
            cin >> T[i][j];
        }
    }
    cout << (check()? "Yes" : "No") << endl;
    return 0;
}
0