結果
問題 | No.211 素数サイコロと合成数サイコロ (1) |
ユーザー | yoshikyoto |
提出日時 | 2015-05-22 22:25:45 |
言語 | Scala(Beta) (3.4.0) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,191 bytes |
コンパイル時間 | 8,984 ms |
コンパイル使用メモリ | 270,152 KB |
実行使用メモリ | 65,340 KB |
最終ジャッジ日時 | 2024-06-29 02:02:10 |
合計ジャッジ時間 | 37,610 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | MLE | - |
testcase_02 | MLE | - |
testcase_03 | MLE | - |
testcase_04 | MLE | - |
testcase_05 | MLE | - |
testcase_06 | MLE | - |
testcase_07 | MLE | - |
testcase_08 | MLE | - |
testcase_09 | MLE | - |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
ソースコード
import java.util.Scanner object Main { def main(args: Array[String]): Unit = { val sc = new Scanner(System.in) val k = sc.nextInt(); val p: List[Int] = List(2, 3, 5, 7, 11, 13) val q: List[Int] = List(4, 6, 8, 9, 10, 12) var cnt = 0; for(i <- p; j <- q) yield { if(i * j == k) cnt += 1; } println(cnt.toDouble / (p.length * q.length).toDouble) } /** * P16 */ def drop[T](n: Int, list: List[T]): List[T] = { def f(i: Int)(n: Int, list: List[T]): List[T] = (i, n, list) match { case (_, _, Nil) => Nil case (1, n, car :: cdr) => f(n)(n, cdr) case (i, n, car :: cdr) => car :: f(i-1)(n, cdr) } f(n)(n, list) } /* def d[T](i: Int, n: Int, list: List[T]): List[T] = (i, n, list) match { case (_, _, Nil) => Nil case (1, n, car :: cdr) => d(n, n, cdr) case (i, n, car :: cdr) => car :: d(i-1, n, cdr) } */ /** * P12 */ /* def decode[T](list: List[List[T]]): List[T] = list match { case Nil => Nil case List(n, v) :: cdr => for(i <- 1 to n) yield {v} :: cdr } */ /** * P11 */ def encode[T](list: List[T]): List[(Int, T)] = list match { case Nil => Nil case car :: cdr => { val (first, second) = list.span(x => x == car) (first.length, car) :: encode(second) } } /** * P10 */ def encodeModified[T](list: List[T]): List[Any] = list match { case Nil => Nil case first :: second :: cdr if first != second => first :: encodeModified(second :: cdr) case car :: cdr => { val (first, second) = list.span(x => x == car) (first.length, car) :: encodeModified(second) } } /** * P09 */ def pack[T](list: List[T]): List[List[T]] = list match { case Nil => Nil case car :: cdr => { val (first, second) = list.span(x => x == car) first :: pack(second) } } /** * P08 */ def compress[T](list: List[T]): List[T] = list match { case first :: second :: cdr if first == second => compress(first :: cdr) case car :: cdr => car :: compress(cdr) case Nil => Nil } /** * P07 */ def flatten(list: List[Any]): List[Any] = list.flatMap { case l: List[_] => flatten(l) case elm => List(elm) } /** * P06 */ def isParindrome[T](list: List[T]): Boolean = list == list.reverse /** * P05 */ def reverse[T](list: List[T]): List[T] = list.foldLeft(List.empty[T])((x, y) => y :: x) /** * P04 */ def length[T](list: List[T]): Int = list match { case Nil => 0; case car :: cdr => 1 + length(cdr) } /** * P03 */ def nth[T](n: Int, list: List[T]): T = (n, list) match { case (0, car :: cdr) => car case (m, car :: cdr) => nth(m-1, cdr) case _ => throw new Exception } /** * P02 */ def penultimate[T](list: List[T]): T = list match { case first :: second :: Nil => first case car :: cdr => last(cdr) case _ => throw new Exception } /** * P01 */ def last[T](list: List[T]): T = list match { case car :: Nil => car case car :: cdr => last(cdr) case _ => throw new Exception } }