結果

問題 No.2441 行列累乗
ユーザー momoyuumomoyuu
提出日時 2023-08-25 22:18:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 3,430 ms
コンパイル使用メモリ 251,132 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 22:18:10
合計ジャッジ時間 3,863 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template< typename T >
vector<vector<T>> mattimes(vector<vector<T>> &A,vector<vector<T>> &B){
    assert(A.size()==B.size());
    int n = A.size();
    vector<vector<T>> res(n,vector<T>(n,0));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++)res[i][j]+=A[i][k]*B[k][j];
    return res;
}

template< typename T >
vector<T> mattimes(vector<vector<T>> &A,vector<T> &B){
    assert(A.size()==B.size());
    int n = A.size();
    vector<T> res(n,0);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)res[i]+=A[i][j]*B[j];
    return res;
}

template< typename T >
vector<vector<T>> matpow(vector<vector<T>> a,ll k){
    int n = a.size();
    vector<vector<T>> res(n,vector<T>(n,0));
    for(int i=0;i<n;i++)res[i][i] = T(1);
    for(;k;k>>=1){
        if(k&1) res = mattimes<T>(res,a);
        a = mattimes<T>(a,a);
    }
    return res;
}

int main(){
    vector<vector<ll>> m(2,vector<ll>(2,0));
    cin>>m[0][0]>>m[0][1]>>m[1][0]>>m[1][1];
    m = matpow<ll>(m,3);
    for(int i = 0;i<2;i++){
        for(int j = 0;j<2;j++){
            if(j) cout<<" ";
            cout<<m[i][j];
        }
        cout<<endl;
    }
    
}
0