結果

問題 No.598 オーバーフローファンタジー
ユーザー 💕💖💞💕💖💞
提出日時 2018-03-08 10:35:16
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,126 bytes
コンパイル時間 10,506 ms
コンパイル使用メモリ 444,116 KB
実行使用メモリ 98,232 KB
最終ジャッジ日時 2024-04-30 17:19:49
合計ジャッジ時間 21,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
63,896 KB
testcase_01 AC 304 ms
98,232 KB
testcase_02 AC 300 ms
60,492 KB
testcase_03 AC 303 ms
60,396 KB
testcase_04 AC 308 ms
60,484 KB
testcase_05 AC 313 ms
60,384 KB
testcase_06 WA -
testcase_07 AC 314 ms
60,304 KB
testcase_08 AC 297 ms
60,480 KB
testcase_09 AC 289 ms
60,528 KB
testcase_10 AC 281 ms
60,472 KB
testcase_11 AC 294 ms
60,452 KB
testcase_12 AC 282 ms
60,396 KB
testcase_13 AC 280 ms
60,452 KB
testcase_14 AC 287 ms
60,460 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 289 ms
60,388 KB
testcase_18 AC 286 ms
60,364 KB
testcase_19 WA -
testcase_20 AC 284 ms
60,444 KB
testcase_21 WA -
testcase_22 AC 281 ms
60,464 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^
Main.kt:24:14: warning: variable 'cure' initializer is redundant
  var cure = 0
             ^
Main.kt:31:13: warning: name shadowed: sum
        val sum = xb + bb*scan
            ^
Main.kt:32:13: warning: name shadowed: sumstr
        val sumstr = java.lang.Integer.toBinaryString(sum).padStart(n, '0')
            ^

ソースコード

diff #

fun main(args:Array<String>) {
  val n = readLine()!!.toInt()

  val x = readLine()!!.toInt()

  val a = readLine()!!.toInt()

  val b = readLine()!!.toInt()

  // 通常攻撃での減産
  val normal = Math.ceil(x.toDouble() / a).toInt()

  
  // 補数
  val xb = java.lang.Integer.toBinaryString(x).toInt(2) 
  val bb = java.lang.Integer.toBinaryString(b).toInt(2)
  

  //val searchRange = (1..normal+1).toList()
  
  var size = normal
  var mid = size/2

  var cure = 0
  master@while(true) {
    val sum = xb + bb*mid
    val sumstr = java.lang.Integer.toBinaryString(sum).padStart(n, '0')
    if( sumstr[0] == '1' ) {
      // start under search
      for( scan in (mid downTo 0) ) {
        val sum = xb + bb*scan
        val sumstr = java.lang.Integer.toBinaryString(sum).padStart(n, '0')
        cure = scan
        if( sumstr[0] == '1' )
          break@master
      }
    } else { 
      mid = (mid + size+1)/2
    }
    if(mid == size) {
      // 探索失敗
      cure = normal + 1
      break@master
    }
  }
  //println(normal)
  //println(cure)
  val output = listOf(normal, cure).min()
  println(output)
}
0