結果

問題 No.1595 The Final Digit
ユーザー emakemak
提出日時 2021-07-09 22:32:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,364 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 202,552 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 09:48:13
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

vector<ll> mul(vector<ll> x, vector<ll> y) {
    vector<ll> z(9);
    for(int i=0; i<3; i++) for(int j=0; j<3; j++) for(int k=0; k<3; k++){
        z[3*i+j] += x[3*i+k] * y[3*k+j];
    }
    for(int i=0; i<9; i++) z[i] = z[i]%10;
    return z;
}

vector<ll> pow(vector<ll> x, ll k) {
    if(k==1) return x;
    if(k%2) return mul(pow(x, k-1), x);
    vector<ll> z = pow(x, k/2);
    return mul(z, z);
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    ll p, q, r, k;
    cin >> p >> q >> r >> k;

    vector<ll> x = {
        1, 1, 1, 1, 0, 0, 0, 1, 0
    };

    vector<ll> z = pow(x, k-3);

    ll ans = r%10*z[0] + q%10*z[1] + p%10*z[2];
    cout << ans % 10 << endl;


    return 0;
}
0