結果

問題 No.205 マージして辞書順最小
ユーザー くわいくわい
提出日時 2015-11-20 21:14:47
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,104 ms / 5,000 ms
コード長 834 bytes
コンパイル時間 11,177 ms
コンパイル使用メモリ 260,500 KB
実行使用メモリ 62,412 KB
最終ジャッジ日時 2023-08-10 11:57:46
合計ジャッジ時間 29,755 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 920 ms
61,716 KB
testcase_01 AC 928 ms
61,864 KB
testcase_02 AC 991 ms
62,068 KB
testcase_03 AC 1,013 ms
62,196 KB
testcase_04 AC 981 ms
62,060 KB
testcase_05 AC 1,012 ms
62,412 KB
testcase_06 AC 964 ms
61,788 KB
testcase_07 AC 1,039 ms
62,256 KB
testcase_08 AC 1,030 ms
62,160 KB
testcase_09 AC 1,032 ms
62,060 KB
testcase_10 AC 1,084 ms
62,332 KB
testcase_11 AC 1,104 ms
62,180 KB
testcase_12 AC 1,086 ms
62,268 KB
testcase_13 AC 1,050 ms
62,228 KB
testcase_14 AC 975 ms
61,924 KB
testcase_15 AC 944 ms
61,540 KB
testcase_16 AC 926 ms
61,768 KB
testcase_17 AC 926 ms
61,940 KB
testcase_18 AC 927 ms
61,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
  }
}
0