結果

問題 No.1644 Eight Digits
ユーザー 👑 箱
提出日時 2021-08-13 21:28:30
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 601 ms / 1,000 ms
コード長 1,505 bytes
コンパイル時間 12,509 ms
コンパイル使用メモリ 440,032 KB
実行使用メモリ 77,292 KB
最終ジャッジ日時 2024-04-14 16:44:38
合計ジャッジ時間 30,748 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 588 ms
77,184 KB
testcase_01 AC 595 ms
77,020 KB
testcase_02 AC 589 ms
76,988 KB
testcase_03 AC 593 ms
77,128 KB
testcase_04 AC 585 ms
77,096 KB
testcase_05 AC 590 ms
77,060 KB
testcase_06 AC 586 ms
76,964 KB
testcase_07 AC 592 ms
77,056 KB
testcase_08 AC 589 ms
77,224 KB
testcase_09 AC 595 ms
77,148 KB
testcase_10 AC 594 ms
77,072 KB
testcase_11 AC 599 ms
76,932 KB
testcase_12 AC 586 ms
77,292 KB
testcase_13 AC 596 ms
77,096 KB
testcase_14 AC 582 ms
77,076 KB
testcase_15 AC 588 ms
77,028 KB
testcase_16 AC 582 ms
77,084 KB
testcase_17 AC 590 ms
77,060 KB
testcase_18 AC 579 ms
77,092 KB
testcase_19 AC 581 ms
76,968 KB
testcase_20 AC 601 ms
77,084 KB
testcase_21 AC 592 ms
76,964 KB
testcase_22 AC 600 ms
77,264 KB
testcase_23 AC 588 ms
76,964 KB
testcase_24 AC 589 ms
77,024 KB
testcase_25 AC 600 ms
77,020 KB
testcase_26 AC 599 ms
77,268 KB
testcase_27 AC 600 ms
77,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val k = nextInt()
    val p = (1..8).toMutableList()
    var ans = 0
    do {
        val n = p.joinToString("").toInt()
        if (n % k == 0) ans++
    } while(nextPermutation(p))
    println(ans)
}

fun nextPermutation(array: MutableList<Int>): Boolean {
    var tmp: Int
    for (i in array.size - 2 downTo 0) {
        if (array[i] < array[i + 1]) {
            for (j in array.size - 1 downTo i + 1) {
                if (array[j] > array[i]) {
                    tmp = array[i]
                    array[i] = array[j]
                    array[j] = tmp

                    val tmpArray = array.takeLast(array.size - (i + 1)).sorted()
                    tmpArray.forEachIndexed { index, e ->
                        array[i + 1 + index] = e
                    }

                    return true
                }
            }
        }
    }
    return false
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", 1.shl(26)).start()
}

// 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