結果

問題 No.52 よくある文字列の問題
ユーザー purple_jwlpurple_jwl
提出日時 2016-11-01 16:18:46
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,005 ms / 5,000 ms
コード長 561 bytes
コンパイル時間 10,614 ms
コンパイル使用メモリ 253,476 KB
実行使用メモリ 62,884 KB
最終ジャッジ日時 2023-09-12 06:55:58
合計ジャッジ時間 21,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 923 ms
62,420 KB
testcase_01 AC 934 ms
62,224 KB
testcase_02 AC 946 ms
62,556 KB
testcase_03 AC 954 ms
62,520 KB
testcase_04 AC 1,005 ms
62,808 KB
testcase_05 AC 1,000 ms
62,884 KB
testcase_06 AC 983 ms
62,816 KB
testcase_07 AC 971 ms
62,536 KB
testcase_08 AC 971 ms
62,148 KB
testcase_09 AC 955 ms
62,252 KB
testcase_10 AC 957 ms
62,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn
import scala.collection.mutable.Stack

object Main {
  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine
    val st = Stack[Array[String]]()
    var ans = Set[String]()

    st.push(Array(s, ""))
    while (!st.isEmpty) {
      val oldStr = st.top(0)
      val newStr = st.top(1)
      st.pop

      if (oldStr.length == 0) {
        ans += newStr
      } else {
        st.push(Array(oldStr.tail, newStr + oldStr.head))
        st.push(Array(oldStr.init, newStr + oldStr.last))
      }
    }

    println(ans.size)
  }
}
0