結果

問題 No.314 ケンケンパ
ユーザー くわいくわい
提出日時 2015-12-10 16:17:13
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 948 ms / 1,000 ms
コード長 473 bytes
コンパイル時間 7,624 ms
コンパイル使用メモリ 235,420 KB
実行使用メモリ 61,968 KB
最終ジャッジ日時 2023-09-11 22:45:19
合計ジャッジ時間 27,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 933 ms
61,884 KB
testcase_01 AC 906 ms
61,636 KB
testcase_02 AC 931 ms
61,664 KB
testcase_03 AC 938 ms
61,616 KB
testcase_04 AC 920 ms
61,688 KB
testcase_05 AC 904 ms
61,908 KB
testcase_06 AC 912 ms
61,540 KB
testcase_07 AC 907 ms
61,680 KB
testcase_08 AC 903 ms
61,516 KB
testcase_09 AC 912 ms
61,720 KB
testcase_10 AC 922 ms
61,688 KB
testcase_11 AC 922 ms
61,448 KB
testcase_12 AC 901 ms
61,648 KB
testcase_13 AC 897 ms
61,728 KB
testcase_14 AC 908 ms
61,528 KB
testcase_15 AC 906 ms
61,488 KB
testcase_16 AC 894 ms
61,592 KB
testcase_17 AC 898 ms
61,500 KB
testcase_18 AC 930 ms
61,968 KB
testcase_19 AC 948 ms
61,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.annotation.tailrec
import scala.io.StdIn

object Main extends App {

  val mod: Int = Math.pow(10, 9).toInt + 7

  def proc(n: Int): Int = {

    if (n == 1) return 1

    @tailrec
    def rec(cnt: Int, a: Long, b: Long, c: Long): Long = {
      if (cnt <= 2) {
        (a + b + c) % mod
      } else {
        rec(cnt - 1, c, (a + c) % mod, b)
      }
    }

    rec(n, 1, 1, 0).toInt
  }

  val n = StdIn.readInt()
  val result = proc(n)
  println(result)
}
0