結果
| 問題 | No.205 マージして辞書順最小 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-20 21:14:47 |
| 言語 | Scala(Beta) (3.8.2) |
| 結果 |
AC
|
| 実行時間 | 377 ms / 5,000 ms |
| + 744µs | |
| コード長 | 834 bytes |
| 記録 | |
| コンパイル時間 | 7,471 ms |
| コンパイル使用メモリ | 263,136 KB |
| 実行使用メモリ | 53,384 KB |
| 最終ジャッジ日時 | 2026-07-28 12:19:08 |
| 合計ジャッジ時間 | 14,443 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)
}
}