結果

問題 No.1830 Balanced Majority
ユーザー rhincodon66rhincodon66
提出日時 2022-02-04 23:02:01
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 14,230 ms
コンパイル使用メモリ 416,116 KB
実行使用メモリ 67,344 KB
平均クエリ数 11.04
最終ジャッジ日時 2023-09-02 05:42:11
合計ジャッジ時間 25,025 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
66,140 KB
testcase_01 AC 304 ms
66,104 KB
testcase_02 AC 300 ms
65,852 KB
testcase_03 AC 301 ms
66,344 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:5:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^

ソースコード

diff #

import kotlin.math.*
import java.lang.StringBuilder
import java.util.*

fun main(args:Array<String>) {
    solve()
}

fun solve(){
    val n = readLine()!!.toInt()
    var l = 1
    var r = n
    var R = n / 2
    var L = 0
    while(r - l > 0){
        val mid = (r + l) / 2
        println("? $mid")
        val s = readLine()!!.toInt()
        val lenL = mid - l + 1
        val lenR = r - mid
        val nextL = s - L
        val nextR = R - s
        if((nextL == 0 && nextR == lenR) || (nextL == lenL && nextR == 0)){
            println("! $mid ${mid + 1}")
            break
        }
        else if(nextL == 0 || nextL == lenL){
            l = mid + 1
            L = s
        }
        else{
            r = mid
            R = s
        }
    }
}
0