結果

問題 No.3224 2×2行列入門
ユーザー Rumain831
提出日時 2025-08-16 18:15:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 83,460 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-16 18:15:39
合計ジャッジ時間 2,238 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
using ll = long long;

struct Matrix{
  int n;
  vector<vector<ll>> a;
  Matrix(int n) :n(n), a(n, vector<ll>(n, 0)){}
  
  Matrix iden(int n){
    Matrix I(n);
    for(int i=0; i<n; i++) I.a[i][i]=1;
    return I;
  }

  Matrix operator*(const Matrix& right) const { //right*base
    Matrix ans(n);
    for(int i=0; i<n; i++){
      for(int k=0; k<n; k++){
        for(int j=0; j<n; j++){
          ans.a[i][j]+=a[i][k]*right.a[k][j];
        }
      }
    }
    return ans;
  }

};

int main(void){
  Matrix A(2), B(2), ans(2);
  for(int i=0; i<2; i++)for(int j=0; j<2; j++) cin >> A.a[i][j];
  for(int i=0; i<2; i++)for(int j=0; j<2; j++) cin >> B.a[i][j];
  ans=A*(B*(A*B));
  for(int i=0; i<2; i++)for(int j=0; j<2; j++) cout << ans.a[i][j] << (j==1?'\n':' ');
  return 0;
}
0