結果

問題 No.103 素因数ゲーム リターンズ
ユーザー バカらっくバカらっく
提出日時 2019-09-30 04:17:50
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,627 bytes
コンパイル時間 13,284 ms
コンパイル使用メモリ 445,752 KB
実行使用メモリ 142,892 KB
最終ジャッジ日時 2024-04-14 07:49:05
合計ジャッジ時間 27,049 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 392 ms
62,992 KB
testcase_01 AC 446 ms
101,044 KB
testcase_02 AC 393 ms
66,832 KB
testcase_03 AC 2,312 ms
118,716 KB
testcase_04 AC 413 ms
63,044 KB
testcase_05 AC 409 ms
63,064 KB
testcase_06 AC 392 ms
59,720 KB
testcase_07 AC 389 ms
59,524 KB
testcase_08 AC 391 ms
59,640 KB
testcase_09 AC 420 ms
62,916 KB
testcase_10 AC 416 ms
63,040 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:4:9: warning: variable 'itemCount' is never used
    val itemCount = readLine()!!.toInt()
        ^

ソースコード

diff #

import kotlin.math.max

fun main(arr:Array<String>) {
    val itemCount = readLine()!!.toInt()
    val numberList = readLine()!!.split(" ").map { it.toInt() }
    val ans = if(canWin(numberList.sorted())) "Alice" else "Bob"
    println(ans)
}

val dic = mutableMapOf<String, Boolean>()
fun canWin(numberList:List<Int>):Boolean {
    if(numberList.isEmpty() || numberList.all { it == 1 }) {
        return false
    }
    val key = numberList.joinToString("-")
    dic[key]?.let { return it }

    val maxIndex = numberList.lastIndex
    var canWin = false
    for(i in (0..maxIndex)) {
        val prime = getPrimeDivide(numberList[i]).toMutableMap()
        for(p in prime.keys) {
            for(j in (1..Math.min(2,prime[p]!!))) {
                val dv = Math.pow(p.toDouble(), j.toDouble()).toInt()
                val newList = numberList.toMutableList()
                newList[i] = numberList[i] / dv
                if(!canWin(newList.sorted())) {
                    canWin = true
                    break
                }
            }
            if(canWin) {
                break
            }
        }
        if(canWin) {
            break
        }
    }
    dic[key] = canWin
    return canWin
}

val primeDic = (0..10000).map { getPrimeDivide(it) }

fun getPrimeDivide(num:Int):Map<Int, Int> {
    var div = 1
    var current = num
    val ret = mutableMapOf<Int, Int>()
    while (current > 1) {
        div++
        var cnt = 0
        while (current % div == 0) {
            cnt++
            current /= div
        }
        if(cnt > 0) {
            ret[div] = cnt
        }
    }
    return ret
}
0