結果

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

ソースコード

diff #

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

const int p = 67;

int mod(int x) {
	x %= p;
	if (x < 0) x += p;
	return x;
}

int main() {
	int A[2][2], B[2][2];
	for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) {
		cin >> A[i][j];
		A[i][j] = mod(A[i][j]);
	}
	for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) {
		cin >> B[i][j];
		B[i][j] = mod(B[i][j]);
	}

	// 変数: a,b,c,d
	// 4つの方程式
	// a,b,c,d を 0~66 で全探索 (重いが小ケース用)

	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++) {
					int det = mod(a*d - b * c);
					if (det == 0) continue; // 行列式ゼロは除く

					// 方程式をチェック
					int eq1 = mod(a*A[0][0] + c * A[1][0] - B[0][0] * a - B[0][1] * b);
					int eq2 = mod(a*A[0][1] + c * A[1][1] - B[0][0] * c - B[0][1] * d);
					int eq3 = mod(b*A[0][0] + d * A[1][0] - B[1][0] * a - B[1][1] * b);
					int eq4 = mod(b*A[0][1] + d * A[1][1] - B[1][0] * c - B[1][1] * d);

					if (eq1 == 0 && eq2 == 0 && eq3 == 0 && eq4 == 0) {
						cout << "Yes\n";
						return 0;
					}
				}
			}
		}
	}
	cout << "No\n";
	return 0;
}
0