提出 #54579921
ソースコード 拡げる
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 ModCombination(n: Int) { val factorial = Array(n + 1) { ModInt.One }.apply { for (i in 1..n) this[i] = this[i - 1] * i } val factorialInv = Array(n + 1) { ModInt.One }.apply { this[n] = factorial[n].inv() for (i in n downTo 1) this[i - 1] = this[i] * i } fun c(a: Int, b: Int) = if (a >= b) factorial[a] * factorialInv[b] * factorialInv[a - b] else ModInt.Zero } fun Array<ModInt>.sum(): ModInt { var sum = ModInt.Zero for (element in this) sum += element return sum } val mc = ModCombination(1000) fun solve() { val k = readInt() val c = readInts(26) var f = Array(k + 1) { ModInt.Zero } f[0] = ModInt.One for (a in c) { val g = Array(k + 1) { ModInt.Zero } for (i in 0..k) { for (j in 0..min(i, a)) { g[i] += f[i - j] * mc.c(i, j) } } f = g } println(f.sum() - 1) } fun main() { // repeat(readInt()) { solve() } solve() }
提出情報
提出日時 | |
---|---|
問題 | E - Alphabet Tiles |
ユーザ | wangchaohui |
言語 | Kotlin (Kotlin/JVM 1.8.20) |
得点 | 475 |
コード長 | 4325 Byte |
結果 | AC |
実行時間 | 291 ms |
メモリ | 56760 KiB |
ジャッジ結果
セット名 | Sample | All | ||||
---|---|---|---|---|---|---|
得点 / 配点 | 0 / 0 | 475 / 475 | ||||
結果 |
|
|
セット名 | テストケース |
---|---|
Sample | sample00.txt, sample01.txt, sample02.txt |
All | sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt |
ケース名 | 結果 | 実行時間 | メモリ |
---|---|---|---|
sample00.txt | AC | 51 ms | 38064 KiB |
sample01.txt | AC | 57 ms | 38528 KiB |
sample02.txt | AC | 291 ms | 56664 KiB |
testcase00.txt | AC | 74 ms | 41312 KiB |
testcase01.txt | AC | 72 ms | 40556 KiB |
testcase02.txt | AC | 70 ms | 40564 KiB |
testcase03.txt | AC | 85 ms | 47880 KiB |
testcase04.txt | AC | 105 ms | 55960 KiB |
testcase05.txt | AC | 80 ms | 44248 KiB |
testcase06.txt | AC | 220 ms | 56332 KiB |
testcase07.txt | AC | 147 ms | 56556 KiB |
testcase08.txt | AC | 137 ms | 56540 KiB |
testcase09.txt | AC | 61 ms | 38644 KiB |
testcase10.txt | AC | 203 ms | 56516 KiB |
testcase11.txt | AC | 171 ms | 56540 KiB |
testcase12.txt | AC | 98 ms | 55676 KiB |
testcase13.txt | AC | 55 ms | 38060 KiB |
testcase14.txt | AC | 164 ms | 56500 KiB |
testcase15.txt | AC | 93 ms | 50888 KiB |
testcase16.txt | AC | 187 ms | 56760 KiB |
testcase17.txt | AC | 78 ms | 42320 KiB |
testcase18.txt | AC | 59 ms | 38472 KiB |