結果

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

ソースコード

diff #

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

template<typename T>
vector<vector<T>> multima(const vector<vector<T>> &A,const vector<vector<T>> &B){
    assert(A.at(0).size() == B.size() && B.size());
    int H = A.size(),W = B.at(0).size();
    vector<vector<T>> ret(H,vector<T>(W));
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        for(int l=0; l<A.at(i).size(); l++){
            ret.at(i).at(k) += A.at(i).at(l)*B.at(l).at(k);
        }
    }
    return ret; //計算できる行列のみ.
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<vector<long long>> A(2,vector<long long>(2)),B = A;
    for(auto &h : A) for(auto &w : h) cin >> w;
    for(auto &h : B) for(auto &w : h) cin >> w;

    auto D = multima(multima(multima(A,B),A),B);
    cout << D.at(0).at(0) << " " << D.at(0).at(1) << endl;
    cout << D.at(1).at(0) << " " << D.at(1).at(1) << endl;
}
0