結果
問題 |
No.3225 2×2行列相似判定 〜easy〜
|
ユーザー |
|
提出日時 | 2025-08-08 21:27:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,486 bytes |
コンパイル時間 | 3,819 ms |
コンパイル使用メモリ | 257,792 KB |
実行使用メモリ | 15,940 KB |
最終ジャッジ日時 | 2025-08-08 21:27:50 |
合計ジャッジ時間 | 7,970 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 TLE * 2 |
other | AC * 10 TLE * 3 -- * 20 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using mint = atcoder::static_modint<67>; using ll = long long; template <class T, size_t N> struct Matrix { std::array<std::array<T, N>, N> A{}; Matrix() {} Matrix(const std::array<std::array<T, N>, N> &M) : A(M){} Matrix(const std::vector<std::vector<T>> &M) { for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ A[i][j] = M[i][j]; } } } const std::array<T, N>& operator[](int i) const { return A[i]; } std::array<T, N>& operator[](int i) { return A[i]; } Matrix& operator+=(const Matrix& rhs) { for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ A[i][j] += rhs[i][j]; } } return *this; } Matrix& operator-=(const Matrix& rhs) { for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ A[i][j] -= rhs[i][j]; } } return *this; } Matrix& operator*=(const Matrix& rhs) { std::array<std::array<T, N>, N> res{}; for(size_t i = 0; i < N; i++){ for(size_t j = 0; j < N; j++){ for(size_t k = 0; k < N; k++){ res[i][j] += A[i][k] * rhs[k][j]; } } } swap(A, res); return *this; } Matrix& operator+() const { return *this; } Matrix& operator-() const { return Matrix() - *this; } friend Matrix operator+(const Matrix& lhs, const Matrix& rhs) { return Matrix(lhs) += rhs; } friend Matrix operator-(const Matrix& lhs, const Matrix& rhs) { return Matrix(lhs) -= rhs; } friend Matrix operator*(const Matrix& lhs, const Matrix& rhs) { return Matrix(lhs) *= rhs; } friend bool operator==(const Matrix& lhs, const Matrix& rhs) { return (lhs.A == rhs.A); } friend bool operator!=(const Matrix& lhs, const Matrix& rhs) { return (lhs.A != rhs.A); } Matrix pow(long long v){ Matrix res, temp = A; for(size_t i = 0; i < N; i++)res[i][i] = 1; while(v){ if(v & 1)res *= temp; temp *= temp; v >>= 1; } return res; } friend std::ostream& operator << (std::ostream &os, const Matrix& rhs) noexcept { for(size_t i = 0; i < N; i++){ if(i) os << '\n'; for(size_t j = 0; j < N; j++){ os << (j ? " " : "") << rhs[i][j]; } } return os; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); Matrix<mint, 2> A, B, C; for(int y = 0; y < 2; y++){ for(int x = 0; x < 2; x++){ int v; cin >> v; A[y][x] = v; } } for(int y = 0; y < 2; y++){ for(int x = 0; x < 2; x++){ int v; cin >> v; B[y][x] = v; } } for(int a = 0; a < 67; a++){ for(int b = 0; b < 67; b++){ for(int c = 0; c < 67; c++){ for(int d = 0; d < 67; d++){ if((a * d - b * c) % 67 == 0) continue; C = Matrix<mint, 2>({{a, b}, {c, d}}); if(C * A == B * C){ cout << "Yes\n"; return 0; } } } } } cout << "No\n"; }