結果

問題 No.1595 The Final Digit
ユーザー grun1301grun1301
提出日時 2021-07-10 13:47:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 88,472 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 19:10:05
合計ジャッジ時間 3,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string.h>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

using mat = vector<vl>;

mat mul(mat &A, mat&B){
    mat C(A.size(), vl(B[0].size()));
    rep(i,A.size()){
        rep(k,B.size()){
            rep(j,B[0].size()){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % 100;
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(), vl(A.size()));
    rep(i,A.size()){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mul(B,A);
        A = mul(A,A);
        n >>= 1;
    }
    return B;
}


int main(){
    ll p,q,r,K;
    cin >> p >> q >> r >> K;
    mat A(3,vl(3));
    A[0][0] = 1; A[0][1] = 1; A[0][2] = 1;
    A[1][0] = 1; A[1][1] = 0; A[1][2] = 0;
    A[2][0] = 0; A[2][1] = 1; A[2][2] = 0;
    A = pow(A,K-3);

    ll pk = A[0][0] * 0 + A[0][1] * 0 + A[0][2] * 1;
    ll qk = A[0][0] * 0 + A[0][1] * 1 + A[0][2] * 0;
    ll rk = A[0][0] * 1 + A[0][1] * 0 + A[0][2] * 0;

    pk %= 10;
    qk %= 10;
    rk %= 10;
    ll ans = p * pk + q* qk + r * rk;
    cout << ans% 10 << endl;

    return 0;
}
0