結果
問題 | No.1631 Sorting Integers (Multiple of K) Easy |
ユーザー | 箱星 |
提出日時 | 2021-07-30 21:31:32 |
言語 | Kotlin (1.9.23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,547 bytes |
コンパイル時間 | 14,319 ms |
コンパイル使用メモリ | 443,448 KB |
実行使用メモリ | 85,216 KB |
最終ジャッジ日時 | 2024-09-15 23:09:42 |
合計ジャッジ時間 | 23,457 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 293 ms
53,180 KB |
testcase_01 | AC | 289 ms
85,216 KB |
testcase_02 | AC | 291 ms
49,856 KB |
testcase_03 | AC | 334 ms
49,756 KB |
testcase_04 | AC | 289 ms
49,584 KB |
testcase_05 | AC | 291 ms
49,624 KB |
testcase_06 | AC | 291 ms
49,680 KB |
testcase_07 | AC | 293 ms
49,740 KB |
testcase_08 | AC | 290 ms
49,620 KB |
testcase_09 | AC | 292 ms
49,760 KB |
testcase_10 | AC | 290 ms
49,852 KB |
testcase_11 | AC | 289 ms
49,512 KB |
testcase_12 | AC | 289 ms
49,724 KB |
testcase_13 | AC | 288 ms
49,628 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val k = nextInt() val c = IntArray(9) { nextInt() } var ans = 0L val pow10 = IntArray(n) { 1 } for (i in 0 until n - 1) { pow10[i + 1] = pow10[i] * 10 % k } fun dfs(r: Int, step: Int, c1: Int, c2: Int, c3: Int, c4: Int, c5: Int, c6: Int, c7: Int, c8: Int, c9: Int) { if (step == n) { if (r == 0) ans++ } else { if (c1 > 0) { val r2 = (r + pow10[step] * 1) % k dfs(r2, step + 1, c1 - 1, c2, c3, c4, c5, c6, c7, c8, c9) } if (c2 > 0) { val r2 = (r + pow10[step] * 2) % k dfs(r2, step + 1, c1, c2 - 1, c3, c4, c5, c6, c7, c8, c9) } if (c3 > 0) { val r2 = (r + pow10[step] * 3) % k dfs(r2, step + 1, c1, c2, c3 - 1, c4, c5, c6, c7, c8, c9) } if (c4 > 0) { val r2 = (r + pow10[step] * 4) % k dfs(r2, step + 1, c1, c2, c3, c4 - 1, c5, c6, c7, c8, c9) } if (c5 > 0) { val r2 = (r + pow10[step] * 5) % k dfs(r2, step + 1, c1, c2, c3, c4, c5 - 1, c6, c7, c8, c9) } if (c6 > 0) { val r2 = (r + pow10[step] * 6) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6 - 1, c7, c8, c9) } if (c7 > 0) { val r2 = (r + pow10[step] * 7) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6, c7 - 1, c8, c9) } if (c8 > 0) { val r2 = (r + pow10[step] * 8) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6, c7, c8 - 1, c9) } if (c9 > 0) { val r2 = (r + pow10[step] * 9) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6, c7, c8, c9 - 1) } } } dfs(0, 0, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8]) println(ans) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.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() // endregion