結果
| 問題 |
No.102 トランプを奪え
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-09-29 19:30:50 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 466 ms / 5,000 ms |
| コード長 | 1,982 bytes |
| コンパイル時間 | 13,726 ms |
| コンパイル使用メモリ | 447,844 KB |
| 実行使用メモリ | 59,968 KB |
| 最終ジャッジ日時 | 2024-10-03 04:34:06 |
| 合計ジャッジ時間 | 19,066 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
^
Main.kt:28:77: warning: no cast needed
return (0..13).map { (0..13).map { (0..13).map { (0..13).map { null as Result? }.toMutableList() }.toMutableList() }.toMutableList() }.toMutableList()
^
ソースコード
import kotlin.math.max
fun main(arr:Array<String>) {
val cards = readLine()!!.split(" ").map { it.toInt() }.sorted()
val result = Proc(cards).canWin(cards)
val ans = when{
result == Proc.Result.Win -> {
"Taro"
}
result == Proc.Result.Lose -> {
"Jiro"
}
else -> {
"Draw"
}
}
println(ans)
}
class Proc(val cards:List<Int>) {
val dic = initDic()
enum class Result {
Win,
Lose,
Draw
}
fun initDic():MutableList<MutableList<MutableList<MutableList<Result?>>>> {
return (0..13).map { (0..13).map { (0..13).map { (0..13).map { null as Result? }.toMutableList() }.toMutableList() }.toMutableList() }.toMutableList()
}
public fun canWin(cardList:List<Int>):Result {
if(cardList.sum() == 0) {
return Result.Lose
}
dic[cardList[0]][cardList[1]][cardList[2]][cardList[3]]?.let {
return it
}
val maxIndex = cardList.size - 1
var ifWin = false
var ifDraw = false
for(i in (0..maxIndex)) {
if(cardList[i] == 0) {
continue
}
val maxCount = Math.min(3, cardList[i])
for(j in (maxCount downTo 1)) {
val newList = cardList.toMutableList()
newList[i] -= j
val ret = canWin(newList.sorted())
if(ret == Result.Lose) {
ifWin = true
break
} else if(ret == Result.Draw) {
ifDraw = true
}
}
if(ifWin) {
break
}
}
var result = Result.Lose
if(ifWin) {
result = Result.Win
} else if(ifDraw) {
result = Result.Draw
}
dic[cardList[0]][cardList[1]][cardList[2]][cardList[3]] = result
return result
}
}
バカらっく