結果
問題 | No.1629 Sorting Integers (SUM of M) |
ユーザー | yakamoto |
提出日時 | 2021-07-30 21:36:33 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 324 ms / 2,000 ms |
コード長 | 5,064 bytes |
コンパイル時間 | 17,498 ms |
コンパイル使用メモリ | 464,336 KB |
実行使用メモリ | 55,288 KB |
最終ジャッジ日時 | 2024-09-15 23:18:30 |
合計ジャッジ時間 | 24,148 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 286 ms
49,876 KB |
testcase_01 | AC | 292 ms
49,672 KB |
testcase_02 | AC | 293 ms
49,776 KB |
testcase_03 | AC | 290 ms
49,880 KB |
testcase_04 | AC | 311 ms
52,188 KB |
testcase_05 | AC | 289 ms
50,176 KB |
testcase_06 | AC | 296 ms
50,552 KB |
testcase_07 | AC | 322 ms
53,200 KB |
testcase_08 | AC | 310 ms
52,124 KB |
testcase_09 | AC | 322 ms
52,928 KB |
testcase_10 | AC | 303 ms
52,480 KB |
testcase_11 | AC | 304 ms
51,604 KB |
testcase_12 | AC | 308 ms
52,352 KB |
testcase_13 | AC | 314 ms
52,560 KB |
testcase_14 | AC | 310 ms
51,704 KB |
testcase_15 | AC | 320 ms
52,752 KB |
testcase_16 | AC | 319 ms
52,844 KB |
testcase_17 | AC | 324 ms
55,288 KB |
コンパイルメッセージ
Main.kt:189:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: LongArray) { ^ Main.kt:193:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: IntArray) { ^ Main.kt:197:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debug(a: BooleanArray) { ^ Main.kt:201:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} ^ Main.kt:203:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debugDim(A: Array<LongArray>) { ^ Main.kt:210:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debugDim(A: Array<IntArray>) { ^ Main.kt:217:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun debugDim(A: Array<BooleanArray>) { ^ Main.kt:234:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} ^
ソースコード
import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.lang.AssertionError import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 1_000_000_007 private fun powMod(a: Long, n: Long, mod: Int): Long { if (n == 0L) return 1 val res = powMod(a * a % mod, n / 2, mod) return if (n % 2 == 1L) res * a % mod else res } /** * @param mod 逆数計算するため素数でないといけない */ class Comb(n: Int, val mod: Int) { val F = LongArray(n + 1) val I = LongArray(n + 1) // n>=modでも処理できるように、*modを別扱いにする val cntF = IntArray(n + 1) // Fの*modの数 val x = IntArray(n + 1) // 数値から*modを取り除いた値 val cntX = IntArray(n + 1) // xの*modの数 init { F[0] = 1 I[0] = 1 for (i in 1..n) { x[i] = i if(x[i] % mod == 0) { val j = i/mod cntX[i] = cntX[j] + 1 x[i] = x[j] } F[i] = F[i - 1] * x[i] % mod cntF[i] += cntF[i - 1] + cntX[i] } I[n] = powMod(F[n], (mod - 2).toLong(), mod) for (i in n - 1 downTo 0) { I[i] = I[i + 1] * x[i + 1] % mod } } fun comb(n: Int, k: Int): Long { if (n < k) return 0L val c = cntF[n] - cntF[k] - cntF[n - k] return if (c > 0) 0 else F[n] * I[k] % mod * I[n - k] % mod } fun perm(n: Int, k: Int): Long { val c = cntF[n] - cntF[n - k] return if (c > 0) 0 else F[n] * I[n - k] % mod } fun inv(x: Int): Long { val c = cntF[x] - cntF[x - 1] return if (c > 0) 0 else I[x] * F[x - 1] % mod } /** * nのグループからk回重複ありで選ぶ組み合わせ数 * n - 1のしきりとkの○で考える */ fun H(n: Int, k: Int) = comb(n + k - 1, k) } class Solver(stream: InputStream, private val out: java.io.PrintWriter) { private val reader = BufferedReader(InputStreamReader(stream), 32768) fun solve() { val N = ni() val C = na(9) val comb = Comb(N, MOD) var ans = 0L var pow10 = 0L var ten = 1L for (i in 0 until N) { pow10 = (pow10 + ten) %MOD ten = ten *10 %MOD } for (num in 0 until 9) { if (C[num] == 0) continue var coef = comb.F[N - 1] for (j in 0 until 9) { val c = if (j == num) C[j] - 1 else C[j] if (c == 0) continue coef = coef *comb.I[c]%MOD } ans = (ans + pow10 *(num+1)%MOD *coef%MOD) %MOD } out.println(ans) } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private fun next(): String { while (tokenizer == null || !tokenizer!!.hasMoreTokens()) { tokenizer = StringTokenizer(reader.readLine()) } return tokenizer!!.nextToken() } private fun ni() = next().toInt() private fun nl() = next().toLong() private fun ns() = next() private fun na(n: Int, offset: Int = 0): IntArray { return IntArray(n) { ni() + offset } } private fun nal(n: Int, offset: Int = 0): LongArray { val res = LongArray(n) for (i in 0 until n) { res[i] = nl() + offset } return res } private fun na2(n: Int, offset: Int = 0): Array<IntArray> { val a = Array(2){IntArray(n)} for (i in 0 until n) { for (e in a) { e[i] = ni() + offset } } return a } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } /** * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと */ private inline fun debug(a: LongArray) { debug { a.joinToString(" ") } } private inline fun debug(a: IntArray) { debug { a.joinToString(" ") } } private inline fun debug(a: BooleanArray) { debug { toString(a) } } private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")} private inline fun debugDim(A: Array<LongArray>) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array<IntArray>) { if (isDebug) { for (a in A) { debug(a) } } } private inline fun debugDim(A: Array<BooleanArray>) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()} private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())} companion object { // TestRunnerから呼びたいので単純なmainじゃだめ fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() } } } /** * judgeから呼ばれる */ fun main() = Solver.main()