結果
問題 |
No.3224 2×2行列入門
|
ユーザー |
|
提出日時 | 2025-08-08 22:36:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,289 bytes |
コンパイル時間 | 1,945 ms |
コンパイル使用メモリ | 204,752 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-08 22:36:42 |
合計ジャッジ時間 | 2,593 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long struct Matrix { int n, m; vector<vector<int>> a; Matrix(){} Matrix(int _n, int _m){ n = _n, m = _m; a.resize(n); for (int i = 0; i < n; i++) a[i].resize(m); } Matrix(vector<vector<int>> o){ n = o.size(); m = o[0].size(); a.resize(n); for (int i = 0; i < n; i++) { a[i].resize(m); for (int j = 0; j < m; j++) a[i][j] = o[i][j]; } } Matrix operator *(const Matrix& rhs) { assert(m == rhs.n); int nc = n, mc = rhs.m; Matrix C(n, m); for (int i = 0; i < nc; i++) { for (int j = 0; j < mc; j++) { C.a[i][j] = 0; for (int k = 0; k < m; k++) C.a[i][j] += a[i][k] * rhs.a[k][j]; } } return C; } friend ostream& operator<<(ostream& os, const Matrix& mat) { for (int i = 0; i < mat.n; i++) { for (int j = 0; j < mat.m; j++) { os << mat.a[i][j]; if (j + 1 < mat.m) os << " "; } os << "\n"; } return os; } }; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a1, b1, c1, d1; int a2, b2, c2, d2; cin >> a1 >> b1 >> c1 >> d1; cin >> a2 >> b2 >> c2 >> d2; Matrix M1({{a1, b1}, {c1, d1}}); Matrix M2({{a2, b2}, {c2, d2}}); cout << M1 * M2 * M1 * M2; }