結果

問題 No.102 トランプを奪え
ユーザー バカらっくバカらっく
提出日時 2019-09-29 19:30:50
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 455 ms / 5,000 ms
コード長 1,982 bytes
コンパイル時間 13,689 ms
コンパイル使用メモリ 450,152 KB
実行使用メモリ 65,104 KB
最終ジャッジ日時 2024-04-14 07:21:17
合計ジャッジ時間 19,131 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 346 ms
60,572 KB
testcase_01 AC 347 ms
60,468 KB
testcase_02 AC 363 ms
60,704 KB
testcase_03 AC 347 ms
60,640 KB
testcase_04 AC 352 ms
60,736 KB
testcase_05 AC 370 ms
62,844 KB
testcase_06 AC 374 ms
62,672 KB
testcase_07 AC 362 ms
60,528 KB
testcase_08 AC 370 ms
62,804 KB
testcase_09 AC 455 ms
65,104 KB
testcase_10 AC 451 ms
65,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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()
                                                                            ^

ソースコード

diff #

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
    }
}
0