結果

問題 No.1644 Eight Digits
ユーザー 👑 箱星箱星
提出日時 2021-08-13 21:28:30
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 629 ms / 1,000 ms
コード長 1,505 bytes
コンパイル時間 14,363 ms
コンパイル使用メモリ 443,028 KB
実行使用メモリ 77,360 KB
最終ジャッジ日時 2024-05-17 13:28:57
合計ジャッジ時間 29,890 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 530 ms
77,168 KB
testcase_01 AC 524 ms
77,260 KB
testcase_02 AC 523 ms
77,208 KB
testcase_03 AC 520 ms
77,140 KB
testcase_04 AC 510 ms
77,076 KB
testcase_05 AC 514 ms
77,152 KB
testcase_06 AC 535 ms
77,072 KB
testcase_07 AC 502 ms
77,248 KB
testcase_08 AC 515 ms
77,156 KB
testcase_09 AC 536 ms
77,180 KB
testcase_10 AC 519 ms
77,228 KB
testcase_11 AC 508 ms
77,276 KB
testcase_12 AC 548 ms
77,120 KB
testcase_13 AC 519 ms
77,148 KB
testcase_14 AC 518 ms
77,148 KB
testcase_15 AC 629 ms
77,188 KB
testcase_16 AC 533 ms
77,060 KB
testcase_17 AC 509 ms
77,012 KB
testcase_18 AC 525 ms
77,064 KB
testcase_19 AC 544 ms
77,100 KB
testcase_20 AC 504 ms
77,156 KB
testcase_21 AC 517 ms
77,100 KB
testcase_22 AC 533 ms
77,360 KB
testcase_23 AC 514 ms
77,244 KB
testcase_24 AC 524 ms
77,320 KB
testcase_25 AC 514 ms
77,088 KB
testcase_26 AC 508 ms
77,140 KB
testcase_27 AC 513 ms
77,148 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