結果

問題 No.2 素因数ゲーム
コンテスト
ユーザー バカらっく
提出日時 2019-08-24 07:10:56
言語 Kotlin
(2.4.10 + ACL)
コンパイル:
kotlinc -cp /opt/aclib/ac_library.jar _filename_ -include-runtime -d main.jar
実行:
java -cp main.jar:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 269 ms / 5,000 ms
+ 180µs
コード長 1,561 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,526 ms
コンパイル使用メモリ 507,656 KB
実行使用メモリ 49,552 KB
最終ジャッジ日時 2026-09-27 04:17:44
合計ジャッジ時間 14,153 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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