結果
| 問題 |
No.1595 The Final Digit
|
| コンテスト | |
| ユーザー |
tabae326
|
| 提出日時 | 2021-07-09 21:46:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,984 bytes |
| コンパイル時間 | 2,387 ms |
| コンパイル使用メモリ | 207,764 KB |
| 最終ジャッジ日時 | 2025-01-22 21:23:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#include <atcoder/modint>
using mint = atcoder::static_modint<10>;
namespace mat {
template <class T> using matrix = vector<vector<T>>;
template <class T>
matrix<T> idMat(int n) {
matrix<T> res(n, vector<T>(n, 0));
rep(i, 0, n) res[i][i] = 1;
return res;
}
template <class T>
matrix<T> matMul(matrix<T> a, matrix<T> b) {
assert(a.size() && b.size());
assert(a.size() == b[0].size() && a[0].size() == b.size());
matrix<T> res(a.size(), vector<T>(b.size(), 0));
rep(i, 0, a.size()) {
rep(j, 0, b.size()) {
rep(k, 0, b.size()) {
res[i][j] += a[i][k] * b[k][j];
}
}
}
return res;
}
template <class T>
vector<T> vecMul(matrix<T> a, vector<T> b) {
assert(a.size() && b.size());
assert(a[0].size() == b.size());
vector<T> res(b.size(), 0);
rep(i, 0, a.size()) {
rep(j, 0, b.size()) {
res[i] += a[i][j] * b[j];
}
}
return res;
}
template <class T>
matrix<T> matPow(matrix<T> a, ll p) {
assert(a.size() && a.size() == a[0].size());
matrix<T> res(a.size(), vector<T>(a.size(), 0));
rep(i, 0, a.size()) res[i][i] = 1;
while(p) {
if(p & 1) res = matMul(res, a);
a = matMul(a, a);
p /= 2;
}
return res;
}
}
void solve() {
ll p, q, r, k;
cin >> p >> q >> r >> k;
vector<mint> v = {p, q, r};
vector<vector<mint>> x = {{0, 1, 0}, {0, 0, 1}, {1, 1, 1}};
x = mat::matPow(x, k-3);
auto ans = mat::vecMul(x, v);
cout << ans[2].val() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
tabae326