結果
| 問題 | No.103 素因数ゲーム リターンズ |
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-09-30 04:17:50 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,627 bytes |
| コンパイル時間 | 14,464 ms |
| コンパイル使用メモリ | 446,484 KB |
| 実行使用メモリ | 118,348 KB |
| 最終ジャッジ日時 | 2024-10-03 04:57:28 |
| 合計ジャッジ時間 | 27,591 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 6 TLE * 1 -- * 13 |
コンパイルメッセージ
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()
^
ソースコード
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
}
バカらっく