結果

問題 No.3231 2×2行列相似判定 〜hard〜
ユーザー jiangxinyang
提出日時 2025-08-08 22:27:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 194,348 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-08 22:27:12
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 200005;
const int INF = 0x3f3f3f3f;
ll powmod(ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y & 1) res = res * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return res;
}
ll add(ll a, ll b) {
    return (a + b) % mod;
}
ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}
ll mul(ll a, ll b) {
    return a * b % mod;
}
ll A[2][2], B[2][2];
int main() {
    cin >> A[0][0] >> A[0][1];
    cin >> A[1][0] >> A[1][1];
    cin >> B[0][0] >> B[0][1];
    cin >> B[1][0] >> B[1][1];
    ll trA = add(A[0][0], A[1][1]);
    ll detA = sub(mul(A[0][0], A[1][1]), mul(A[0][1], A[1][0]));
    ll trB = add(B[0][0], B[1][1]);
    ll detB = sub(mul(B[0][0], B[1][1]), mul(B[0][1], B[1][0]));
    if (trA != trB || detA != detB) {
        cout << "No\n";
        return 0;
    }
    if (sub(mul(trA, trA), mul(4, detA)) != 0) {
        cout << "Yes\n";
    } else {
        ll t = mul(trA, (mod + 1) / 2);
        bool ok1 = (A[0][0] == t && A[1][1] == t && A[0][1] == 0 && A[1][0] == 0);
        bool ok2 = (B[0][0] == t && B[1][1] == t && B[0][1] == 0 && B[1][0] == 0);
        if (ok1 == ok2) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }

    return 0;
}
0