結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー 👑 箱星箱星
提出日時 2021-07-30 21:27:51
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,213 bytes
コンパイル時間 15,121 ms
コンパイル使用メモリ 425,448 KB
実行使用メモリ 83,432 KB
最終ジャッジ日時 2023-10-14 03:30:17
合計ジャッジ時間 24,717 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
53,460 KB
testcase_01 AC 276 ms
83,432 KB
testcase_02 AC 279 ms
54,648 KB
testcase_03 AC 321 ms
54,956 KB
testcase_04 AC 274 ms
50,192 KB
testcase_05 AC 273 ms
50,304 KB
testcase_06 AC 275 ms
50,228 KB
testcase_07 AC 275 ms
50,144 KB
testcase_08 AC 273 ms
50,552 KB
testcase_09 AC 282 ms
52,428 KB
testcase_10 AC 282 ms
52,352 KB
testcase_11 AC 272 ms
50,168 KB
testcase_12 AC 273 ms
50,188 KB
testcase_13 AC 275 ms
50,272 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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, a: IntArray) {
        if (step == n) {
            if (r == 0) ans++
        } else {
            for (i in 0 until 9) {
                if (a[i] > 0) {
                    val r2 = (r + pow10[step] * (i + 1)) % k
                    val a2 = a.copyOf()
                    a2[i]--
                    dfs(r2, step + 1, a2)
                }
            }
        }
    }
    dfs(0, 0, c)
    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
0