結果

問題 No.2441 行列累乗
ユーザー twooimptwooimp
提出日時 2023-08-25 21:25:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 173,500 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 21:25:57
合計ジャッジ時間 2,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

vector<vector<ll>> mul(vector<vector<ll>> v1,vector<vector<ll>> v2){
  ll s=v1.size();
  vector<vector<ll>> res(s,vector<ll>(s,0));
  for(ll i=0;i<s;i++){
    for(ll j=0;j<s;j++){
      for(ll k=0;k<s;k++){
        res[i][j]+=v1[i][k]*v2[k][j];
      }
    }
  }
  return res;
}

vector<vector<ll>> modpow(vector<vector<ll>> v,ll n){
  ll s=v.size();
  vector<vector<ll>> res(s,vector<ll>(s,0));
  for(ll i=0;i<s;i++){
    res[i][i]=1;
  }
  while(n>0){
    if(n&1){
      res=mul(res,v);
    }
    v=mul(v,v);
    n>>=1;
  }
  return res;
}

int main(){
  ll m11,m12;
  cin>>m11>>m12;
  ll m21,m22;
  cin>>m21>>m22;
  vector<vector<ll>> v={{m11,m12},{m21,m22}};
  vector<vector<ll>> ans=modpow(v,3);
  cout<<ans[0][0]<<" "<<ans[0][1]<<endl;
  cout<<ans[1][0]<<" "<<ans[1][1]<<endl;
}
0