結果
問題 | No.1202 お菓子の食べ方 |
ユーザー | 👑 箱 |
提出日時 | 2020-11-29 03:41:39 |
言語 | Kotlin (1.9.23) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,030 bytes |
コンパイル時間 | 18,788 ms |
コンパイル使用メモリ | 432,672 KB |
実行使用メモリ | 162,416 KB |
最終ジャッジ日時 | 2023-10-11 02:19:08 |
合計ジャッジ時間 | 83,356 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,608 ms
112,628 KB |
testcase_01 | AC | 1,333 ms
92,364 KB |
testcase_02 | AC | 1,976 ms
153,736 KB |
testcase_03 | AC | 1,800 ms
126,248 KB |
testcase_04 | AC | 1,726 ms
122,892 KB |
testcase_05 | AC | 1,996 ms
153,852 KB |
testcase_06 | AC | 1,873 ms
137,436 KB |
testcase_07 | AC | 1,808 ms
126,232 KB |
testcase_08 | AC | 1,755 ms
124,936 KB |
testcase_09 | AC | 1,966 ms
141,668 KB |
testcase_10 | AC | 637 ms
67,892 KB |
testcase_11 | AC | 972 ms
83,860 KB |
testcase_12 | AC | 1,269 ms
97,092 KB |
testcase_13 | AC | 795 ms
80,480 KB |
testcase_14 | AC | 1,570 ms
121,544 KB |
testcase_15 | AC | 1,185 ms
112,500 KB |
testcase_16 | AC | 1,586 ms
124,156 KB |
testcase_17 | AC | 1,373 ms
113,564 KB |
testcase_18 | AC | 1,004 ms
82,880 KB |
testcase_19 | AC | 1,334 ms
117,696 KB |
testcase_20 | AC | 978 ms
75,784 KB |
testcase_21 | AC | 1,730 ms
148,536 KB |
testcase_22 | AC | 1,641 ms
145,692 KB |
testcase_23 | AC | 1,883 ms
151,916 KB |
testcase_24 | AC | 1,904 ms
152,344 KB |
testcase_25 | AC | 662 ms
67,588 KB |
testcase_26 | AC | 1,775 ms
148,296 KB |
testcase_27 | AC | 1,858 ms
151,904 KB |
testcase_28 | AC | 1,127 ms
96,332 KB |
testcase_29 | AC | 1,798 ms
147,904 KB |
testcase_30 | AC | 282 ms
52,796 KB |
testcase_31 | AC | 283 ms
52,952 KB |
testcase_32 | AC | 287 ms
52,808 KB |
testcase_33 | AC | 285 ms
52,928 KB |
testcase_34 | AC | 284 ms
52,872 KB |
testcase_35 | AC | 284 ms
52,968 KB |
testcase_36 | AC | 285 ms
52,988 KB |
testcase_37 | AC | 282 ms
52,812 KB |
testcase_38 | AC | 283 ms
53,076 KB |
testcase_39 | AC | 286 ms
52,824 KB |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
ソースコード
import java.io.InputStream import java.io.PrintWriter import java.util.* // ModInt // region class ModInt(x: Long) { companion object { const val MOD = 1000000007L //const val MOD = 998244353L } val x = (x % MOD + MOD) % MOD operator fun plus(other: ModInt): ModInt { return ModInt(x + other.x) } operator fun minus(other: ModInt): ModInt { return ModInt(x - other.x) } operator fun times(other: ModInt): ModInt { return ModInt(x * other.x) } operator fun div(other: ModInt): ModInt { return this * other.inv() } fun pow(exp: Long): ModInt { if (exp == 0L) return ModInt(1L) var a = pow(exp shr 1) a *= a if (exp and 1L == 0L) return a return this * a } fun inv(): ModInt { return this.pow(MOD - 2) } override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false other as ModInt if (x != other.x) return false return true } override fun hashCode(): Int { return x.hashCode() } override fun toString(): String { return "$x" } } val fac = mutableListOf<ModInt>() val invfac = mutableListOf<ModInt>() fun fact(n: Long, b: Boolean): ModInt { if (fac.count() == 0) { fac.add(ModInt(1)) invfac.add(ModInt(1)) } while (fac.count() <= n) { fac.add(fac.last() * ModInt(fac.count().toLong())) invfac.add(fac.last().inv()) } return if (b) { fac[n.toInt()] } else { invfac[n.toInt()] } } fun comb(n: Long, k: Long): ModInt { if (k !in 0..n) return ModInt(0) return fact(n, true) * fact(k, false) * fact(n - k, false) } // endregion fun PrintWriter.solve() = with(FastScanner(System.`in`)) { val n = nextInt() val m = nextInt() val s = Array(n) { LongArray(m) { nextLong() } } var ans = ModInt(0) for (x in 0 until n) { for (y in 0 until m) { val v = s[x][y] ans += comb(x + y + v - 1, x.toLong()) * comb(y + v - 1, y.toLong()) val v1 = if (y + 1 < m) s[x][y + 1] else 0 ans += comb(x + y.toLong(), x.toLong()) * (comb(x + y + v, v - 1) - comb(x + y + v1, v1 - 1)) val v2 = if (x + 1 < n) s[x + 1][y] else 0 ans += comb(x + y.toLong(), x.toLong()) * (comb(x + y + v, v - 1) - comb(x + y + v2, v2 - 1)) } } println(ans) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = s.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() }