結果

問題 No.1595 The Final Digit
ユーザー shiomusubi496shiomusubi496
提出日時 2021-07-09 21:35:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 207,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 07:56:55
合計ジャッジ時間 2,902 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll=long long;
using Mat=std::vector<std::vector<ll>>;
constexpr ll mod=10;
Mat operator*(Mat a,Mat b){
    Mat res(a.size(),std::vector<ll>(b[0].size()));
    for(int i=0;i<(int)a.size();i++){
        for(int j=0;j<(int)b[0].size();j++){
            for(int k=0;k<(int)b.size();k++)(res[i][j]+=a[i][k]*b[k][j])%=mod;
        }
    }
    return res;
}
Mat mat_e(unsigned int sz){
    Mat res(sz,std::vector<ll>(sz));
    for(int i=0;i<(int)sz;i++)res[i][i]=1;
    return res;
}
Mat mat_pow(Mat a,ll b){
    if(!b)return mat_e(a.size());
    if(b&1)return mat_pow(a,b-1)*a;
    return mat_pow(a*a,b/2);
}
signed main(){
    int p,q,r,K; cin>>p>>q>>r>>K;
    vector<vector<int>> A{{1,1,1},{1,0,0},{0,1,0}};
    vector<vector<int>> B{{r%10},{q%10},{p%10}};
    cout<<(mat_pow(A,K-1)*B)[2][0]<<endl;
}
0