Submission #54098601
Source Code Expand
import MutableIntMap.Companion.mutableIntMapOf import java.io.* import java.util.* import kotlin.collections.* import kotlin.math.* 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 = 998244353 } } fun Array<ModInt>.sum(): ModInt { var sum = ModInt.Zero for (element in this) sum += element return sum } fun solve() { val n = readLong() + 1 val m = readLong() var ans = ModInt.Zero for (i in 0 until 60) if (m hasBit i) { val h = 1L shl i val i1 = n / (2 * h) * h val i2 = (n - i1 * 2 - h).coerceAtLeast(0) ans += ModInt.from(i1 + i2) } println(ans) } fun main() { // repeat(readInt()) { solve() } solve() }
Submission Info
Submission Time | |
---|---|
Task | D - Masked Popcount |
User | wangchaohui |
Language | Kotlin (Kotlin/JVM 1.8.20) |
Score | 400 |
Code Size | 4004 Byte |
Status | AC |
Exec Time | 47 ms |
Memory | 38424 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 45 ms | 38108 KiB |
sample_02.txt | AC | 43 ms | 38032 KiB |
sample_03.txt | AC | 42 ms | 37492 KiB |
test_01.txt | AC | 46 ms | 38308 KiB |
test_02.txt | AC | 43 ms | 38212 KiB |
test_03.txt | AC | 42 ms | 37840 KiB |
test_04.txt | AC | 43 ms | 38196 KiB |
test_05.txt | AC | 41 ms | 37968 KiB |
test_06.txt | AC | 44 ms | 38356 KiB |
test_07.txt | AC | 43 ms | 38092 KiB |
test_08.txt | AC | 41 ms | 37932 KiB |
test_09.txt | AC | 45 ms | 38420 KiB |
test_10.txt | AC | 43 ms | 38208 KiB |
test_11.txt | AC | 44 ms | 38220 KiB |
test_12.txt | AC | 45 ms | 38120 KiB |
test_13.txt | AC | 47 ms | 38224 KiB |
test_14.txt | AC | 47 ms | 38056 KiB |
test_15.txt | AC | 45 ms | 38136 KiB |
test_16.txt | AC | 44 ms | 38156 KiB |
test_17.txt | AC | 42 ms | 38416 KiB |
test_18.txt | AC | 43 ms | 38156 KiB |
test_19.txt | AC | 46 ms | 38344 KiB |
test_20.txt | AC | 42 ms | 38268 KiB |
test_21.txt | AC | 46 ms | 38128 KiB |
test_22.txt | AC | 43 ms | 38044 KiB |
test_23.txt | AC | 42 ms | 38296 KiB |
test_24.txt | AC | 46 ms | 38424 KiB |
test_25.txt | AC | 41 ms | 38160 KiB |
test_26.txt | AC | 42 ms | 37980 KiB |
test_27.txt | AC | 42 ms | 38168 KiB |
test_28.txt | AC | 42 ms | 38132 KiB |
test_29.txt | AC | 47 ms | 38224 KiB |
test_30.txt | AC | 44 ms | 38264 KiB |
test_31.txt | AC | 43 ms | 38152 KiB |
test_32.txt | AC | 42 ms | 38024 KiB |
test_33.txt | AC | 43 ms | 38020 KiB |
test_34.txt | AC | 44 ms | 38124 KiB |
test_35.txt | AC | 45 ms | 38224 KiB |
test_36.txt | AC | 43 ms | 38140 KiB |
test_37.txt | AC | 42 ms | 38048 KiB |
test_38.txt | AC | 45 ms | 38336 KiB |
test_39.txt | AC | 41 ms | 38172 KiB |
test_40.txt | AC | 46 ms | 38360 KiB |
test_41.txt | AC | 42 ms | 37444 KiB |
test_42.txt | AC | 46 ms | 38180 KiB |
test_43.txt | AC | 46 ms | 38092 KiB |
test_44.txt | AC | 46 ms | 38212 KiB |
test_45.txt | AC | 44 ms | 37980 KiB |
test_46.txt | AC | 42 ms | 38188 KiB |