Advertisement
Guest User

Untitled

a guest
May 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import scala.io.StdIn
  2.  
  3. object Solution extends App {
  4.  
  5. def runLength(resp: String): List[Int] = if (resp.isEmpty) Nil else {
  6. val (front, back) = resp.span(_ == resp.head)
  7. front.size :: runLength(back)
  8. }
  9.  
  10. def sliceWith(windows: List[Int], resp: String): List[Int] = windows match {
  11. case Nil => Nil
  12. case x::xs =>
  13. val (front, back) = resp.splitAt(x)
  14. val (zeros, ones) = front.span(_ == '0')
  15. zeros.size :: ones.size :: sliceWith(xs, back)
  16. }
  17.  
  18. for(i <-1 to StdIn.readLine.toInt) {
  19. val Array(n, b, f) = StdIn.readLine.split(" ").map(_.toInt)
  20.  
  21. println(("0"*16 ++ "1"*16)*(n/32 + 1) take n)
  22.  
  23. val windows = (runLength(StdIn.readLine) /: Seq(8, 4, 2, 1)) { case (windows, j) =>
  24. println(("0"*j ++ "1"*j)*(n/(j*2) + 1) take n)
  25. sliceWith(windows, StdIn.readLine)
  26. }
  27.  
  28. val output = for {
  29. (b, n) <- windows.take(n).zipWithIndex if b == 0
  30. } yield n
  31.  
  32. println(output mkString " ")
  33.  
  34. val ans = StdIn.readLine.toInt
  35. assert(ans == 1)
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement