結果

問題 No.1595 The Final Digit
ユーザー yuruhiyayuruhiya
提出日時 2021-07-09 21:43:22
言語 Crystal
(1.10.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 387 bytes
コンパイル時間 20,711 ms
コンパイル使用メモリ 256,288 KB
実行使用メモリ 4,520 KB
最終ジャッジ日時 2023-09-14 08:17:16
合計ジャッジ時間 21,731 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

p, q, r, k = read_line.split.map(&.to_i64)
k -= 3
p, q, r = {p, q, r}.map { |x| x % 10 }
count = [nil.as(Int64?)] * 1000
array = [] of Int64
k.times do |now|
  x = p*100 + q*10 + r
  if cnt = count[x]
    cycle = now - cnt
    pos = (k - cnt) % cycle
    puts array[cnt + pos] % 10
    exit
  end
  count[x] = now
  array << x
  p, q, r = {q, r, p + q + r}.map { |x| x % 10 }
end
puts r
0