結果

問題 No.1595 The Final Digit
ユーザー lavoxlavox
提出日時 2021-07-09 21:53:30
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 1,688 ms
使用メモリ 37,436 KB
最終ジャッジ日時 2023-02-01 23:13:38
合計ジャッジ時間 4,762 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 91 ms
37,300 KB
testcase_01 AC 92 ms
37,332 KB
testcase_02 AC 91 ms
37,248 KB
testcase_03 AC 91 ms
37,416 KB
testcase_04 AC 94 ms
37,436 KB
testcase_05 AC 89 ms
37,324 KB
testcase_06 AC 91 ms
37,248 KB
testcase_07 AC 89 ms
37,232 KB
testcase_08 AC 89 ms
37,256 KB
testcase_09 AC 89 ms
37,304 KB
testcase_10 AC 92 ms
37,336 KB
testcase_11 AC 89 ms
37,260 KB
testcase_12 AC 91 ms
37,244 KB
testcase_13 AC 91 ms
37,300 KB
testcase_14 AC 92 ms
37,316 KB
testcase_15 AC 90 ms
37,324 KB
testcase_16 AC 91 ms
37,324 KB
testcase_17 AC 89 ms
37,284 KB
testcase_18 AC 92 ms
37,320 KB
testcase_19 AC 93 ms
37,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int p = Integer.parseInt(sc.next()) % 10;
		int q = Integer.parseInt(sc.next()) % 10;
		int r = Integer.parseInt(sc.next()) % 10;
		long K = Long.parseLong(sc.next());
		sc.close();
		
		long[] cnt = new long[1000];
		long i = 3;
		long ans = 0;
		while ( true ) {
			if ( i == K ) {
				ans = r;
				break;
			}
			if ( cnt[100 * p + 10 * q + r] > 0 ) {
				long per = i - cnt[100 * p + 10 * q + r];
				long x = (K - i) / per;
				i += x * per;
				i++;
				for ( ; i <= K ; i++ ) {
					int n = (p + q + r) % 10;
					p = q;
					q = r;
					r = n;
				}
				ans = r;
				break;
			} else {
				cnt[100 * p + 10 * q + r] = i++;
			}
			int n = (p + q + r) % 10;
			p = q;
			q = r;
			r = n;
		}

		System.out.println(ans);
	}
}
0