結果

問題 No.392 2分木をたどれ
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-10 04:42:31
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 13,767 ms
コンパイル使用メモリ 426,300 KB
実行使用メモリ 54,100 KB
最終ジャッジ日時 2023-08-12 20:44:22
合計ジャッジ時間 15,762 ms
ジャッジサーバーID
(参考情報)
judge2 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 316 ms
52,844 KB
testcase_01 AC 543 ms
54,040 KB
testcase_02 AC 546 ms
54,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:2:11: warning: parameter 'args' is never used
fun main( args : Array<String> ) {
          ^
Main.kt:13:9: warning: name shadowed: m
    val m = Math.pow(2.toDouble(), p.toDouble())
        ^

ソースコード

diff #

data class Data(val index:Int, val name:String)
fun main( args : Array<String> ) {
  val m = readLine()!!.toInt()
  val scans = (1..m).map {
    readLine()!!.toInt()
  }
  // build
  val xx = mutableListOf( Data(0,"") )
  
  var cnt = 0
  var buff = mutableListOf( Data(0, "") )
  (1..11).map { p ->
    val m = Math.pow(2.toDouble(), p.toDouble())
    val next = mutableListOf<Data>()
    (0..m.toInt()-1).map { i ->
      cnt++
      val target = i/2
      val prev_name = buff[target].name
      val data = when {
        i%2 == 0 -> Data(cnt, prev_name + "L")
        else -> Data(cnt, prev_name + "R")
      }
      xx.add( data )
      next.add( data )
    }
    buff = next
  }
  scans.map { s ->
    xx.filter { it.index == s }.first().name.let{ println(it) }
  }
}
0