結果

問題 No.1595 The Final Digit
ユーザー e869120e869120
提出日時 2021-05-03 13:35:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 65,484 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 06:41:05
合計ジャッジ時間 1,895 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

long long p, q, r, K;
long long A[1 << 18];
long long used[1009];

int main() {
	// Step #1. Input
	cin >> p >> q >> r >> K;
	A[1] = p % 10LL;
	A[2] = q % 10LL;
	A[3] = r % 10LL;
	used[A[1] * 1 + A[2] * 10 + A[3] * 100] = 3;

	// Step #2. Solve
	long long res = K;
	for (long long i = 4; i <= K; i++) {
		A[i] = (A[i - 1] + A[i - 2] + A[i - 3]) % 10LL;
		long long nex = A[i - 2] * 1 + A[i - 1] * 10 + A[i] * 100;
		if (used[nex] != 0LL) {
			long long cycle = i - used[nex];
			res = (K - used[nex]) % cycle + used[nex];
			break;
		}
		used[nex] = i;
	}

	// Step #3. Output
	cout << A[res] << endl;
	return 0;
}
0