結果
問題 | No.1595 The Final Digit |
ユーザー |
|
提出日時 | 2021-07-17 00:29:29 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 631 bytes |
コンパイル時間 | 10,128 ms |
コンパイル使用メモリ | 223,436 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 12:01:36 |
合計ジャッジ時間 | 10,785 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
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]) }