結果

問題 No.3225 2×2行列相似判定 〜easy〜
ユーザー nonon
提出日時 2025-08-12 14:25:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,003 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 3,223 ms
コンパイル使用メモリ 276,604 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-12 14:25:56
合計ジャッジ時間 21,867 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }

using V = array<ll, 2>;
using Mat = array<V, 2>;

const int p = 67;
Mat mul(Mat a, Mat b) {
    Mat c = Mat{V{0, 0}, V{0, 0}};
    for (int i = 0; i < 2; i++) {
        for (int k = 0; k < 2; k++) {
            for (int j = 0; j < 2; j++) {
                c[i][j] += a[i][k] * b[k][j];
                c[i][j] %= p;
            }
        }
    }
    return c;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Mat A, B;
    for (int s : {0, 1}) {
        for (int t : {0, 1}) cin >> A[s][t];
    }
    for (int s : {0, 1}) {
        for (int t : {0, 1}) cin >> B[s][t];
    }
    for (int a = 0; a < p; a++) {
        for (int b = 0; b < p; b++) {
            for (int c = 0; c < p; c++) {
                for (int d = 0; d < p; d++) {
                    if (a * d == b * c) continue;
                    Mat P = Mat{V{a, b}, V{c, d}};
                    auto L = mul(P, A);
                    auto R = mul(B, P);
                    if (L == R) {
                        cout << "Yes\n";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "No\n";
}
0