-
-
Save waynejo/5d687471a34ab06fb65e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.{FileOutputStream, FileInputStream} | |
import scala.io.StdIn | |
object Main extends App { | |
Console.setIn(new FileInputStream("B-large-practice.in")) | |
Console.setOut(new FileOutputStream("B-large-practice.out")) | |
def solve(numbers:List[Int]): Int = { | |
if (1 >= numbers.length) 0 | |
else { | |
val index = numbers.zipWithIndex.min._2 | |
val right = numbers.length - 1 | |
val moved = if (index < right - index) index else right - index | |
moved + solve(numbers.take(index) ::: numbers.drop(index + 1)) | |
} | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach { n => | |
val qNum = StdIn.readLine().toInt | |
val numbers = StdIn.readLine().split(" ").map(_.toInt).toList | |
println(s"Case #$n: ${solve(numbers)}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment