Submission #581109
Source Code Expand
Copy
import scala.annotation.tailrec import net.pushl.io.MyConsole // Document: http://www.scala-lang.org/api/current/#package // ----------------------------------------------------------------------------- class Solver(val stdio: MyConsole){ import stdio._ // shadow Console.~ def main() : Unit = { val n,k = nextInt() val a = readIntVector() val r = a.sorted.drop(n-k).foldLeft(0.0)((c,x) => (c+x)/2) println(r) } } // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- object Main { def main(args: Array[String]) : Unit = { val console = new MyConsole(Console.in, Console.out, Console.err) val solver = new Solver(console) solver.main() console.flush() } } package net.pushl.io { import java.io.{BufferedReader, PrintWriter, PrintStream, PushbackReader} class MyConsole(val in: BufferedReader, val _out: PrintStream, val err: PrintStream) { // PrintWriter do not flush automatically val out = new PrintWriter(_out,false) // If argument is null, there are ambiguous which function will be called def print(obj: Any) = out.print(if(obj == null) "null" else obj.toString) def println() = out.println() def println(obj: Any) = out.println(obj) def printf(text: String, args: Any*) = out.printf(text.format(args : _*)) // NOTE: YOU MUST FLUSH BEFORE END OF MAIN def flush() = out.flush() def debugln(obj: Any) = err.println("\u001b[36m" + obj + "\u001b[0m") def readIntVector() : Vector[Int] = parseLineToVector(() => nextInt) def readLongVector() : Vector[Long] = parseLineToVector(() => nextLong) def readStringVector() : Vector[String] = parseLineToVector(() => nextString) def nextInt() : Int = nextLong().toInt def nextBigInt() : BigInt = BigInt(nextString()) def nextBigDecimal( ) : BigDecimal = BigDecimal(nextString()) def nextDouble() : Double = nextString().toDouble def nextLong() : Long = { if(!goNextValuable()) throw new NoSuchElementException("Reading long failed") val sgn = if(peek == '-') -1l else 1 if(sgn == -1l) ignore(read()) if(peek < '0' || '9' < peek) throw new NumberFormatException("readLong found only '-' or no number") @tailrec def readLong(next: Int, cur: Long) : Long = if('0' <= next && next <= '9'){ ignore(read()) // is equal to next readLong(peek, cur*10 + next-'0') } else if(isEnd(next) || isSpaceOrControl(next)) sgn*cur else throw new NumberFormatException("readLong found strange byte $next") val res = readLong(peek,0) skipTrailingSpaces() res } def nextString() : String = { if(!goNextValuable()) throw new NoSuchElementException("Reading String failed") val builder = new StringBuilder @tailrec def appendCode(next: Int) : String = { if(isEnd(next) || isSpaceOrControl(next)){ builder.toString }else{ builder.append(read().toChar) // here we skip. appendCode(peek) } } val res = appendCode(peek) skipTrailingSpaces() res } // TODO: refactoring to marge nextString def readLine() : String = { if(isEnd(peek)) throw new NoSuchElementException("Reading Line failed") skipNewline() val builder = new StringBuilder @tailrec def appendCode(next: Int) : String = { if(isEnd(next) || isNewLine(next)){ builder.toString }else{ builder.append(next.toChar) appendCode(read()) } } appendCode(read()) } // helpers private def ignore[T](x: => T) : Unit = { x; () } private[this] var peeked: Option[Int] = None private[this] var is_first = true protected def read() = { val res = peeked match { case None => in.read() case Some(a) => { peeked = None; a } } is_first = false res } private def peek() = peeked match { case None => { val res = in.read() peeked = Some(res) res } case Some(a) => a } private def isEnd(c: Int) = c == -1 private def isCR(c: Int) = c == 13 private def isLF(c: Int) = c == 10 private def isNewLine(c: Int) = isLF(c) || isCR(c) private def isThereReadable() = !isEnd(peek) private def isSpaceOrControl(c: Int) = (0 <= c && c <= 32) || c == 127 @tailrec final private def goNextNotSpaceNorControl() : Unit = if(isSpaceOrControl(peek)){ ignore(read()) goNextNotSpaceNorControl() } final private def skipTrailingSpaces() : Unit = { @tailrec def skipTrailingSpacesAux() : Unit = { if(!isNewLine(peek) && isSpaceOrControl(peek)){ ignore(read()) skipTrailingSpacesAux() } } skipTrailingSpacesAux() } final private def skipNewline() : Unit = if(!is_first){ if(isCR(peek)) ignore(read()) if(isLF(peek)) ignore(read()) } private def goNextValuable() : Boolean = { goNextNotSpaceNorControl() isThereReadable() } private def parseLineToVector[X](parser: () => X) : Vector[X] = { import scala.collection.immutable.VectorBuilder val vb = new VectorBuilder[X]() skipNewline() @tailrec def parseLineToVectorAux() : Vector[X] = if(isNewLine(peek) || isEnd(peek)) { vb.result }else{ vb += parser() parseLineToVectorAux() } parseLineToVectorAux() } } }
Submission Info
Submission Time | |
---|---|
Task | C - AtCoderプログラミング講座 |
User | tomoki |
Language | Scala (2.9.1) |
Score | 100 |
Code Size | 6114 Byte |
Status | AC |
Exec Time | 896 ms |
Memory | 42864 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 848 ms | 42724 KB |
00_sample_02.txt | AC | 896 ms | 42712 KB |
00_sample_03.txt | AC | 834 ms | 42756 KB |
00_sample_04.txt | AC | 853 ms | 42728 KB |
test_01.txt | AC | 859 ms | 42748 KB |
test_02.txt | AC | 870 ms | 42604 KB |
test_03.txt | AC | 859 ms | 42740 KB |
test_04.txt | AC | 866 ms | 42792 KB |
test_05.txt | AC | 849 ms | 42724 KB |
test_06.txt | AC | 854 ms | 42812 KB |
test_07.txt | AC | 837 ms | 42844 KB |
test_08.txt | AC | 842 ms | 42756 KB |
test_09.txt | AC | 844 ms | 42760 KB |
test_10.txt | AC | 885 ms | 42704 KB |
test_11.txt | AC | 872 ms | 42716 KB |
test_12.txt | AC | 874 ms | 42804 KB |
test_13.txt | AC | 847 ms | 42816 KB |
test_14.txt | AC | 827 ms | 42808 KB |
test_15.txt | AC | 841 ms | 42808 KB |
test_16.txt | AC | 828 ms | 42728 KB |
test_17.txt | AC | 826 ms | 42732 KB |
test_18.txt | AC | 824 ms | 42804 KB |
test_19.txt | AC | 821 ms | 42828 KB |
test_20.txt | AC | 830 ms | 42820 KB |
test_21.txt | AC | 828 ms | 42840 KB |
test_22.txt | AC | 825 ms | 42864 KB |
test_23.txt | AC | 828 ms | 42708 KB |
test_24.txt | AC | 823 ms | 42684 KB |
test_25.txt | AC | 870 ms | 42696 KB |
test_26.txt | AC | 831 ms | 42784 KB |
test_27.txt | AC | 819 ms | 42792 KB |
test_28.txt | AC | 820 ms | 42700 KB |
test_29.txt | AC | 832 ms | 42780 KB |
test_30.txt | AC | 846 ms | 42696 KB |