結果

問題 No.1595 The Final Digit
ユーザー ComiComi
提出日時 2021-07-17 00:29:29
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 11,464 ms
コンパイル使用メモリ 201,644 KB
実行使用メモリ 5,664 KB
最終ジャッジ日時 2023-09-20 16:59:58
合計ジャッジ時間 12,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func main() {
	defer writer.Flush()

	var p, q, r, k int
	fmt.Fscan(reader, &p, &q, &r, &k)

	a := make([]int, 1000000)
	a[1] = p % 10
	a[2] = q % 10
	a[3] = r % 10

	used := make([]int, 1009)
	used[(a[1]+a[2]+a[3])%10] = 3

	ans := k
	for i := 4; i <= k; i++ {
		a[i] = (a[i-1] + a[i-2] + a[i-3]) % 10
		nex := a[i]*100 + a[i-1]*10 + a[i-2]*1
		if used[nex] != 0 {
			cycle := i - used[nex]
			ans = (k-used[nex])%cycle + used[nex]
			break
		}
		used[nex] = i
	}

	fmt.Fprintf(writer, "%v", a[ans])
}
0