Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io.StdIn
- object Solution extends App {
- def runLength(resp: String): List[Int] = if (resp.isEmpty) Nil else {
- val (front, back) = resp.span(_ == resp.head)
- front.size :: runLength(back)
- }
- def sliceWith(windows: List[Int], resp: String): List[Int] = windows match {
- case Nil => Nil
- case x::xs =>
- val (front, back) = resp.splitAt(x)
- val (zeros, ones) = front.span(_ == '0')
- zeros.size :: ones.size :: sliceWith(xs, back)
- }
- for(i <-1 to StdIn.readLine.toInt) {
- val Array(n, b, f) = StdIn.readLine.split(" ").map(_.toInt)
- println(("0"*16 ++ "1"*16)*(n/32 + 1) take n)
- val windows = (runLength(StdIn.readLine) /: Seq(8, 4, 2, 1)) { case (windows, j) =>
- println(("0"*j ++ "1"*j)*(n/(j*2) + 1) take n)
- sliceWith(windows, StdIn.readLine)
- }
- val output = for {
- (b, n) <- windows.take(n).zipWithIndex if b == 0
- } yield n
- println(output mkString " ")
- val ans = StdIn.readLine.toInt
- assert(ans == 1)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement