Submission #54350626
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 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 } } class Matrix( val n: Int, val m: Int, private val initialValue: ModInt = ModInt.Zero ) { val value = Array(n) { Array(m) { initialValue } } fun fill(list: List<Int>) { check(list.size == n * m) list.forEachIndexed { i, a -> value[i / m][i % m] = ModInt.from(a) } } operator fun times(other: Matrix): Matrix { check(m == other.n) val res = Matrix(n, other.m) for (i in 0 until n) { for (j in 0 until other.m) { for (k in 0 until m) { res.value[i][j] += value[i][k] * other.value[k][j] } } } return res } fun pow(exponent: Int) = pow(exponent.toLong()) fun pow(exponent: Long): Matrix { check(n == m) var ans = identity(n) var a = this var b = exponent while (b > 0) { if (b and 1 == 1L) ans *= a a *= a b /= 2 } return ans } companion object { fun identity(n: Int) = Matrix(n, n).apply { for (i in 0 until n) value[i][i] = ModInt.One } } } fun solve() { val n = readLong() var m = n var c = ModInt.from(10) while (m >= 10) { m /= 10 c *= 10 } val a = Matrix(2, 2).apply { fill(listOf(c.value, 1, 0, 1)) } val ans = a.pow(n) * Matrix(2, 1).apply { fill(listOf(0, n.mod(ModInt.MOD))) } println(ans.value[0][0]) } fun main() { // repeat(readInt()) { solve() } solve() }
Submission Info
Submission Time | |
---|---|
Task | D - 88888888 |
User | wangchaohui |
Language | Kotlin (Kotlin/JVM 1.8.20) |
Score | 350 |
Code Size | 4969 Byte |
Status | AC |
Exec Time | 71 ms |
Memory | 42176 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 350 / 350 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 66 ms | 41928 KiB |
example_01.txt | AC | 65 ms | 42036 KiB |
example_02.txt | AC | 69 ms | 42008 KiB |
hand_00.txt | AC | 66 ms | 41888 KiB |
hand_01.txt | AC | 65 ms | 41808 KiB |
hand_02.txt | AC | 66 ms | 41788 KiB |
hand_03.txt | AC | 66 ms | 42000 KiB |
hand_04.txt | AC | 70 ms | 42060 KiB |
hand_05.txt | AC | 67 ms | 41772 KiB |
hand_06.txt | AC | 67 ms | 41720 KiB |
hand_07.txt | AC | 67 ms | 42120 KiB |
hand_08.txt | AC | 65 ms | 41864 KiB |
hand_09.txt | AC | 66 ms | 42076 KiB |
random_00.txt | AC | 69 ms | 42104 KiB |
random_01.txt | AC | 71 ms | 42164 KiB |
random_02.txt | AC | 66 ms | 42020 KiB |
random_03.txt | AC | 68 ms | 42000 KiB |
random_04.txt | AC | 67 ms | 41756 KiB |
random_05.txt | AC | 66 ms | 41888 KiB |
random_06.txt | AC | 67 ms | 41996 KiB |
random_07.txt | AC | 67 ms | 42020 KiB |
random_08.txt | AC | 67 ms | 41860 KiB |
random_09.txt | AC | 69 ms | 42176 KiB |
random_10.txt | AC | 66 ms | 41892 KiB |
random_11.txt | AC | 71 ms | 41936 KiB |
random_12.txt | AC | 62 ms | 41820 KiB |
random_13.txt | AC | 65 ms | 41964 KiB |
random_14.txt | AC | 65 ms | 41812 KiB |