結果
| 問題 |
No.1595 The Final Digit
|
| コンテスト | |
| ユーザー |
yamake
|
| 提出日時 | 2021-07-09 21:41:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,566 bytes |
| コンパイル時間 | 1,906 ms |
| コンパイル使用メモリ | 178,332 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 15:38:00 |
| 合計ジャッジ時間 | 2,789 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
template<typename T>
class Matrix{
public:
int size;
vector<vector<T>> mat;
Matrix(int n){
size=n;
mat.resize(n,vector<T>(n,0));
}
void in(T value,int i,int j){
mat[i][j]+=value;
}
T out(int i,int j){
return mat[i][j];
}
Matrix<T> mul(Matrix<T> A,Matrix<T> B){
int n=A.size;
Matrix<T> res(n);
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
T sum=0;
for(int k=0;k<n;++k){
sum+=A.out(i,k)*B.out(k,j);
sum%=10;
}
res.in(sum,i,j);
}
}
return res;
}
Matrix<T> pow(long long k){
Matrix<T> res(size);
Matrix<T> A(*this);
for(int i=0;i<size;++i)res.in(1,i,i);
while(k>0){
if(k&1)res=mul(res,A);
k/=2;
A=mul(A,A);
}
return res;
}
};
signed main(){
lint p,q,r,k;cin>>p>>q>>r>>k;
p%=10;q%=10;r%=10;
Matrix<lint> mat(3);
rep(i,3)mat.in(1,0,i);
mat.in(1,1,0);mat.in(1,2,1);
mat=mat.pow(k-3);
lint res=mat.out(0,0)*r+mat.out(0,1)*q+mat.out(0,2)*p;
res%=10;
cout<<res<<"\n";
return 0;
}
yamake