結果

問題 No.2 素因数ゲーム
ユーザー バカらっくバカらっく
提出日時 2019-08-24 07:10:56
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 763 ms / 5,000 ms
コード長 1,561 bytes
コンパイル時間 13,263 ms
コンパイル使用メモリ 444,732 KB
実行使用メモリ 60,504 KB
最終ジャッジ日時 2024-04-30 21:20:18
合計ジャッジ時間 25,881 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 317 ms
57,068 KB
testcase_01 AC 316 ms
57,000 KB
testcase_02 AC 346 ms
60,412 KB
testcase_03 AC 329 ms
60,328 KB
testcase_04 AC 330 ms
60,448 KB
testcase_05 AC 329 ms
60,464 KB
testcase_06 AC 331 ms
60,468 KB
testcase_07 AC 335 ms
60,212 KB
testcase_08 AC 343 ms
60,280 KB
testcase_09 AC 346 ms
60,304 KB
testcase_10 AC 335 ms
60,276 KB
testcase_11 AC 335 ms
60,388 KB
testcase_12 AC 340 ms
60,360 KB
testcase_13 AC 356 ms
60,440 KB
testcase_14 AC 337 ms
60,404 KB
testcase_15 AC 333 ms
60,392 KB
testcase_16 AC 330 ms
60,384 KB
testcase_17 AC 334 ms
60,504 KB
testcase_18 AC 346 ms
60,472 KB
testcase_19 AC 567 ms
56,928 KB
testcase_20 AC 497 ms
60,192 KB
testcase_21 AC 763 ms
56,904 KB
testcase_22 AC 347 ms
60,460 KB
testcase_23 AC 351 ms
60,268 KB
testcase_24 AC 340 ms
60,384 KB
testcase_25 AC 345 ms
60,156 KB
testcase_26 AC 337 ms
60,208 KB
testcase_27 AC 344 ms
60,424 KB
testcase_28 AC 342 ms
60,380 KB
testcase_29 AC 337 ms
60,476 KB
testcase_30 AC 353 ms
60,404 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
         ^

ソースコード

diff #

import java.util.*
import kotlin.math.sqrt

fun main(args: Array<String>){
    var num = readLine()!!.toInt()
    var ans = "Bob"
    if(isWin(divPrime(num))) {
        ans = "Alice"
    }
    println(ans)
}

val dictionary = mutableMapOf<Int,MutableMap<String,Boolean>>()
fun isWin(primeList:List<Int>):Boolean {
    if(primeList.size <= 0) {
        return false
    }
    if(!dictionary.containsKey(primeList.size)) {
        dictionary[primeList.size] = mutableMapOf()
    }
    val key = getKey(primeList)
    if(dictionary[primeList.size]!!.containsKey(key)) {
        return dictionary[primeList.size]!![key]!!
    }
    var canWin = false
    for(i in primeList.indices) {
        for(j in 1..primeList[i]) {
            var sublist = primeList.toMutableList()
            sublist[i] -= j
            if(sublist[i] <= 0) {
                sublist.removeAt(i)
            }
            sublist = sublist.sortedDescending().toMutableList()
            if(!isWin(sublist)) {
                canWin = true
                break
            }
        }
    }
    dictionary[primeList.size]!![key] = canWin
    return canWin
}

fun getKey(list: List<Int>):String {
    return list.joinToString("-")
}

fun divPrime(num:Int):List<Int> {
    var temp = num
    var div = 2
    val list = mutableListOf<Int>()
    while (temp > 1) {
        var cnt = 0
        while (temp % div == 0) {
            cnt++
            temp = (temp / div)
        }
        if(cnt > 0) {
            list.add(cnt)
        }
        div++
    }
    return list.sortedDescending()
}
0