結果

問題 No.638 Sum of "not power of 2"
ユーザー 💕💖💞💕💖💞
提出日時 2018-04-05 22:02:20
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 271 ms / 1,000 ms
コード長 685 bytes
コンパイル時間 9,660 ms
コンパイル使用メモリ 434,828 KB
実行使用メモリ 57,176 KB
最終ジャッジ日時 2024-04-30 18:14:44
合計ジャッジ時間 14,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
56,920 KB
testcase_01 AC 264 ms
57,176 KB
testcase_02 AC 266 ms
56,916 KB
testcase_03 AC 263 ms
56,932 KB
testcase_04 AC 259 ms
56,984 KB
testcase_05 AC 268 ms
56,884 KB
testcase_06 AC 268 ms
56,828 KB
testcase_07 AC 265 ms
56,860 KB
testcase_08 AC 258 ms
56,900 KB
testcase_09 AC 264 ms
56,788 KB
testcase_10 AC 271 ms
56,868 KB
testcase_11 AC 256 ms
56,828 KB
testcase_12 AC 269 ms
56,960 KB
testcase_13 AC 268 ms
56,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^

ソースコード

diff #

import java.math.BigDecimal

fun main(args:Array<String>) {
  val n = readLine()!!.toBigDecimal()
  
  val m = ("1" + "0".repeat(18)).toBigDecimal()

  val bs = mutableSetOf<BigDecimal>()
  var tp = 1.toBigDecimal()
  stack@while(true) {
    if( tp > m ) break@stack
    //println(tp) 
    bs.add( tp )
    tp *= 2.toBigDecimal()
  }
  var x = 0.toBigDecimal()
  var control = false
  scan@while(true) {
    x++
    if( bs.contains(x) ) continue@scan
    val y = n - x
    if( !bs.contains(y) && y > 0.toBigDecimal() ) {
      control = true
      break@scan
    }
    if( x > n/2.toBigDecimal() ) break@scan
  }
  if( control )
    println("${x} ${n - x}")
  else 
    println("-1")
}
0