結果

問題 No.1595 The Final Digit
ユーザー olpheolphe
提出日時 2021-07-09 21:26:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 117,748 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 07:42:47
合計ジャッジ時間 2,224 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<vector<long long int>>matrix_product(vector<vector<long long int>>v, vector<vector<long long int>>w) {
	vector<vector<long long int>>ret(v.size(), vector<long long int>(w.front().size()));
	for (int i = 0; i < ret.size(); i++) {
		for (int j = 0; j < ret[i].size(); j++) {
			for (int k = 0; k < w.size(); k++) {
				ret[i][j] += v[i][k] * w[k][j];
				ret[i][j] %= 10;
			}
		}
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M >> K >> L;
	N %= 10, M %= 10, K %= 10;
	vector<vector<long long>>by(3, vector<long long>(3));
	by[0][0] = by[0][1] = by[0][2] = by[1][0] = by[2][1] = 1;
	L -= 3;
	vector<vector<long long>>box(3, vector<long long>(1));
	box[2][0] = N;
	box[1][0] = M;
	box[0][0] = K;
	for (int i = 0; i < 60; i++) {
		if (L >> i & 1) {
			box = matrix_product(by, box);
		}
		by = matrix_product(by, by);
	}
	cout << box[0][0] << endl;
}
0