Submission #4026650
Source Code Expand
import java.io.{InputStream, OutputStream, PrintStream} import java.util.Scanner import scala.annotation.tailrec object Main { def main(args: Array[String]): Unit = { val solver = new Solver(System.in, System.out) solver.solve() } class Solver(in: InputStream, out: OutputStream) { lazy val input = new Scanner(in) lazy val output = new PrintStream(out) def solve(): Unit = { val Array(n, k) = input.nextLine().split(" ").map(_.toInt) val xs = input.nextLine().split(" ").map(_.toInt) output.println(solve(xs.toSet, k)) } def solve(xs: Set[Int], k: Int): Int = { var leftPos = 0 var rightPos = 0 var foundCount = 0 if (xs(0)) { foundCount += 1 } if (foundCount >= k) { return 0 } 1.to(Math.pow(10, 5).toInt).foreach { i => if (xs(i)) { rightPos = i foundCount += 1 } if (foundCount >= k) { val min = leftPos.min(rightPos) val max = leftPos.max(rightPos) return min * 2 + max } if (xs(i * -1)) { leftPos = i foundCount += 1 } if (foundCount >= k) { val min = leftPos.min(rightPos) val max = leftPos.max(rightPos) return min * 2 + max } } 0 } @tailrec final def gcd(m: Int, n: Int): Int = { val (x, y) = if (m > n) (m, n) else (n, m) if (y != 0) gcd(y, x % y) else x } } }
Submission Info
Submission Time | |
---|---|
Task | C - Candles |
User | lambdasawa |
Language | Scala (2.11.7) |
Score | 0 |
Code Size | 1593 Byte |
Status | WA |
Exec Time | 875 ms |
Memory | 66372 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 339 ms | 25280 KB |
0_01.txt | AC | 335 ms | 25376 KB |
0_02.txt | AC | 348 ms | 25280 KB |
0_03.txt | AC | 351 ms | 25412 KB |
1_00.txt | WA | 875 ms | 66372 KB |
1_01.txt | WA | 867 ms | 65468 KB |
1_02.txt | WA | 798 ms | 64088 KB |
1_03.txt | WA | 827 ms | 65612 KB |
1_04.txt | WA | 825 ms | 64924 KB |
1_05.txt | WA | 833 ms | 66108 KB |
1_06.txt | WA | 835 ms | 66268 KB |
1_07.txt | WA | 846 ms | 66132 KB |