結果

問題 No.2441 行列累乗
ユーザー nemutainemutai
提出日時 2023-08-25 21:28:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 205,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 21:28:50
合計ジャッジ時間 3,010 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;

const ll INF=1ll<<60;
ll mod10=1e9+7;
ll mod99=998244353;
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=a;i>=n;--i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

vector<vector<ll>> mul(vector<vector<ll>>& A,vector<vector<ll>>& B){
    ll a1=A.size(),a2=A[0].size();
    ll b1=B.size(),b2=B[0].size();
    vector<vector<ll>> C(a1,vector<ll>(b2));
    for(int i=0;i<a1;i++){
       for(int j=0;j<b2;j++){
            for(int k=0;k<a2;k++){
                C[i][j]+=A[i][k]*B[k][j];
            }
        }
    }
    return C;
}

vector<vector<ll>> mpow(vector<vector<ll>> A,ll n){
    vector<vector<ll>> B(A.size(),vector<ll>(A.size()));
    for(int i=0;i<A.size();i++) B[i][i]=1;
    while(n){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

int main(){


    vvll A(2,vll(2));
    rep(i,2) rep(j,2) cin>>A[i][j];
    vvll B=mpow(A,3);
    rep(i,2) cout<<B[i][0]<<" "<<B[i][1]<<endl;

}
0