提出 #53893982


ソースコード 拡げる

import java.io.*
import java.util.*
import kotlin.collections.*
import kotlin.math.min

val INPUT: InputStream = System.`in`
val OUTPUT: PrintStream = System.out

val _reader = INPUT.bufferedReader()

var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    }
    return _tokenizer.nextToken()
}

fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { readInt() }
fun readIntArray(n: Int) = IntArray(n) { readInt() }
fun readDoubles(n: Int) = List(n) { readDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
fun readLongs(n: Int) = List(n) { readLong() }
fun readLongArray(n: Int) = LongArray(n) { readLong() }

val _writer = PrintWriter(OUTPUT, false)
inline fun output(block: PrintWriter.() -> Unit) {
    _writer.apply(block).flush()
}

class MutableIntMap<K> : LinkedHashMap<K, Int>() {
    override operator fun get(key: K): Int = super.get(key) ?: 0

    fun increment(key: K, value: Int = 1) {
        this[key] = this[key] + value
    }

    companion object {
        fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) =
            MutableIntMap<K>().apply { putAll(pairs) }
    }
}

typealias Pii = Pair<Int, Int>

fun readPii() = readInt() to readInt()
fun readPiis(n: Int) = List(n) { readPii() }

infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0
infix fun Int.xorBit(i: Int): Int = this xor (1 shl i)
infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0
infix fun Long.xorBit(i: Int): Long = this xor (1L shl i)

fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) {
    Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply {
        start()
        join()
    }
}

// #################################################################################################

@JvmInline
value class ModInt private constructor(val value: Int) {
    operator fun plus(other: ModInt) = plus(other.value)
    operator fun plus(other: Int) = from(value + other)
    operator fun minus(other: ModInt) = minus(other.value)
    operator fun minus(other: Int) = from(value - other)
    operator fun times(other: ModInt) = times(other.value)
    operator fun times(other: Int) = from(value.toLong() * other)
    operator fun div(other: ModInt) = times(other.inv())
    operator fun div(other: Int) = div(from(other))

    fun pow(exponent: Int): ModInt {
        var ans = One
        var a = this
        var b = exponent
        while (b > 0) {
            if (b % 2 == 1) ans *= a
            a *= a
            b /= 2
        }
        return ans
    }

    fun inv(): ModInt = pow(MOD - 2)

    override fun toString() = value.toString()

    companion object {
        fun combination(n: Int, k: Int): ModInt {
            check(k in 0..n)
            return (1..k).fold(One) { acc, i -> acc * (n - i + 1) / i }
        }

        fun from(value: Int) = ModInt(value.mod())
        fun from(value: Long) = ModInt(value.mod())
        fun Int.mod() = mod(MOD)
        fun Long.mod() = mod(MOD)
        val Zero = from(0)
        val One = from(1)

        const val MOD = 100
    }
}

fun ask(i: Int, j: Int): ModInt {
    println("? $i $j")
    val a = listOf(31, 41, 59, 26, 53, 58, 97, 93)
//    return ModInt.from(a.subList((1 shl i) * j, (1 shl i) * (j + 1)).sum())//.also { println(it) }
    val value = readInt()
    if (value == -1) System.exit(0)
    return ModInt.from(value)
}

fun solve() {
    val n = readInt()
    val l = readInt()
    val r = readInt()
    fun count(i: Int, j: Int, l: Int, r: Int): Int {
        val i2 = 1 shl i
        val a = i2 * j
        val b = i2 * (j + 1) - 1
        if (l == a && r == b) return 1
        val i1 = 1 shl i - 1
        val m = a + i1
        if (r < m) return count(i - 1, j * 2, l, r)
        if (l >= m) return count(i - 1, j * 2 + 1, l, r)
        var ans = 1
        if (l > a) ans += count(i - 1, j * 2, a, l - 1)
        if (r < b) ans += count(i - 1, j * 2 + 1, r + 1, b)
        return ans.coerceAtMost(count(i - 1, j * 2, l, m - 1) + count(i - 1, j * 2 + 1, m, r))
    }

    fun dfs(i: Int, j: Int, l: Int, r: Int): ModInt {
        val i2 = 1 shl i
        val a = i2 * j
        val b = i2 * (j + 1) - 1
        if (l == a && r == b) return ask(i, j)
        val i1 = 1 shl i - 1
        val m = a + i1
        if (r < m) return dfs(i - 1, j * 2, l, r)
        if (l >= m) return dfs(i - 1, j * 2 + 1, l, r)
        var ans1 = 1
        if (l > a) ans1 += count(i - 1, j * 2, a, l - 1)
        if (r < b) ans1 += count(i - 1, j * 2 + 1, r + 1, b)
        val ans2 = count(i - 1, j * 2, l, m - 1) + count(i - 1, j * 2 + 1, m, r)
        if (ans1 < ans2) {
            var t = ask(i, j)
            if (l > a) t -= dfs(i - 1, j * 2, a, l - 1)
            if (r < b) t -= dfs(i - 1, j * 2 + 1, r + 1, b)
            return t
        }
        return dfs(i - 1, j * 2, l, m - 1) + dfs(i - 1, j * 2 + 1, m, r)
    }

    println("! ${dfs(n, 0, l, r)}")
}

fun main() {
//    repeat(readInt()) { solve() }
    solve()
}

提出情報

提出日時
問題 E - Guess the Sum
ユーザ wangchaohui
言語 Kotlin (Kotlin/JVM 1.8.20)
得点 500
コード長 5398 Byte
結果 AC
実行時間 122 ms
メモリ 44840 KiB

コンパイルエラー

Main.kt:113:9: warning: variable 'a' is never used
    val a = listOf(31, 41, 59, 26, 53, 58, 97, 93)
        ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 38
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 89 ms 44576 KiB
01_random_00.txt AC 89 ms 44840 KiB
01_random_01.txt AC 88 ms 44484 KiB
01_random_02.txt AC 87 ms 44176 KiB
01_random_03.txt AC 91 ms 44580 KiB
01_random_04.txt AC 89 ms 44620 KiB
01_random_05.txt AC 88 ms 44552 KiB
01_random_06.txt AC 93 ms 44828 KiB
01_random_07.txt AC 90 ms 44584 KiB
01_random_08.txt AC 88 ms 44684 KiB
01_random_09.txt AC 87 ms 44572 KiB
01_random_10.txt AC 96 ms 44576 KiB
01_random_11.txt AC 90 ms 44564 KiB
01_random_12.txt AC 90 ms 44548 KiB
01_random_13.txt AC 99 ms 44684 KiB
01_random_14.txt AC 102 ms 44612 KiB
01_random_15.txt AC 116 ms 44560 KiB
01_random_16.txt AC 117 ms 44604 KiB
01_random_17.txt AC 117 ms 44568 KiB
01_random_18.txt AC 120 ms 44508 KiB
01_random_19.txt AC 121 ms 44652 KiB
01_random_20.txt AC 115 ms 44628 KiB
01_random_21.txt AC 122 ms 44796 KiB
01_random_22.txt AC 117 ms 44528 KiB
01_random_23.txt AC 117 ms 44688 KiB
01_random_24.txt AC 119 ms 44528 KiB
01_random_25.txt AC 121 ms 44744 KiB
01_random_26.txt AC 121 ms 44720 KiB
01_random_27.txt AC 117 ms 44772 KiB
01_random_28.txt AC 116 ms 44556 KiB
01_random_29.txt AC 116 ms 44804 KiB
01_random_30.txt AC 121 ms 44652 KiB
01_random_31.txt AC 112 ms 44444 KiB
01_random_32.txt AC 113 ms 44604 KiB
01_random_33.txt AC 115 ms 44252 KiB
01_random_34.txt AC 88 ms 44228 KiB
01_random_35.txt AC 87 ms 44332 KiB
01_random_36.txt AC 87 ms 44324 KiB