fork download
  1. object Main extends App {
  2. val inf = 1e7.toInt
  3.  
  4. def m(eggs: Int, floors: Int): Int = {
  5. val memo = Array.ofDim[Int](eggs+1, floors+1)
  6. for (f <- 2 to floors) memo(0)(f) = inf
  7. for (e <- 0 to eggs) {
  8. memo(e)(0) = 0
  9. memo(e)(1) = 0
  10. }
  11. for (e <- 1 to eggs; f <- 2 to floors) {
  12. memo(e)(f) = inf
  13. for (i <- 0 to floors - 1) {
  14. import scala.math.min
  15. memo(e)(f) = min(memo(e)(f), memo(e-1)(i+1))
  16. memo(e)(f) = min(memo(e)(f), memo(e)(f-i-1))
  17. }
  18. print(s"$e $f ${memo(e)(f)}")
  19. }
  20.  
  21. memo(eggs)(floors)
  22. }
  23.  
  24. print(m(2, 100))
  25. }
  26.  
  27.  
Runtime error #stdin #stdout #stderr 0.42s 322496KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
	at Main$.m(Main.scala:11)
	at Main$.delayedEndpoint$Main$1(Main.scala:24)
	at Main$delayedInit$body.apply(Main.scala:1)
	at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.App$$anonfun$main$1.apply(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
	at scala.App$class.main(App.scala:76)
	at Main$.main(Main.scala:1)
	at Main.main(Main.scala)