結果

問題 No.2267 群の公理
ユーザー eve__fuyuki
提出日時 2023-11-29 12:57:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 198,992 KB
最終ジャッジ日時 2025-02-18 02:23:21
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (a[i][a[j][k]] != a[a[i][j]][k]) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    int e = -1;
    for (int i = 0; i < n; i++) {
        bool is_e = true;
        for (int j = 0; j < n; j++) {
            if (a[i][j] != j || a[j][i] != j) {
                is_e = false;
                break;
            }
        }
        if (is_e) {
            e = i;
            break;
        }
    }
    if (e == -1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        bool has_inv = false;
        for (int j = 0; j < n; j++) {
            if (a[i][j] == e && a[j][i] == e) {
                has_inv = true;
                break;
            }
        }
        if (!has_inv) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
0