結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-20 21:14:47 |
| 言語 | Scala(Beta) (3.6.2) |
| 結果 |
AC
|
| 実行時間 | 1,080 ms / 5,000 ms |
| コード長 | 834 bytes |
| コンパイル時間 | 14,406 ms |
| コンパイル使用メモリ | 257,300 KB |
| 実行使用メモリ | 63,188 KB |
| 最終ジャッジ日時 | 2024-11-16 17:09:56 |
| 合計ジャッジ時間 | 35,378 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
import scala.annotation.tailrec
import scala.io.StdIn
object Problem205 {
def proc(N: Int, S: Seq[String]): String = {
@tailrec
def rec(result: Seq[Char], S: Seq[String]): String = {
if (S.isEmpty) return result.reverse.mkString("")
val sorted = S.sorted
val (next, others) = (sorted.head, sorted.tail)
val nextChar: Char = next.head
val remains: Seq[String] = next.tail match {
case "" => others
case x if x.startsWith("{") => others
case x => (x + "{") +: others
}
rec(nextChar +: result, remains)
}
val padS = S.map(s => s + ("{" * (N - s.length)))
rec(Nil, padS)
}
def main(args: Array[String]) = {
val N = StdIn.readInt()
val S = Seq.fill(N)(StdIn.readLine())
val result: String = proc(N, S)
println(result)
}
}