結果
問題 |
No.2 素因数ゲーム
|
ユーザー |
![]() |
提出日時 | 2019-08-24 07:10:56 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 702 ms / 5,000 ms |
コード長 | 1,561 bytes |
コンパイル時間 | 11,924 ms |
コンパイル使用メモリ | 441,740 KB |
実行使用メモリ | 60,504 KB |
最終ジャッジ日時 | 2024-11-20 19:19:53 |
合計ジャッジ時間 | 23,495 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'args' is never used fun main(args: Array<String>){ ^
ソースコード
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() }