結果

問題 No.58 イカサマなサイコロ
ユーザー バカらっくバカらっく
提出日時 2019-09-22 08:48:38
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 356 ms / 5,000 ms
コード長 1,841 bytes
コンパイル時間 18,234 ms
コンパイル使用メモリ 458,496 KB
実行使用メモリ 54,632 KB
最終ジャッジ日時 2023-10-19 07:05:38
合計ジャッジ時間 23,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 320 ms
54,264 KB
testcase_01 AC 356 ms
54,632 KB
testcase_02 AC 323 ms
54,260 KB
testcase_03 AC 321 ms
54,240 KB
testcase_04 AC 325 ms
54,284 KB
testcase_05 AC 323 ms
54,284 KB
testcase_06 AC 331 ms
54,296 KB
testcase_07 AC 323 ms
54,264 KB
testcase_08 AC 329 ms
54,272 KB
testcase_09 AC 333 ms
54,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^

ソースコード

diff #

import java.lang.Long.sum

fun main(arr:Array<String>) {
    val (dice, ikasama) = (1..2).map { readLine()!!.toInt() }
    val taroPatttern = getIkasamaAns(dice, ikasama)
    val jiroPattern = getAns(dice)
    var winCount = 0.toLong()
    var loseCount = 0.toLong()
    var drawCount = 0.toLong()
    for(i in taroPatttern.keys) {
        winCount += taroPatttern[i]!! * jiroPattern.filter { it.key < i }.map { it.value }.sum()
        drawCount += taroPatttern[i]!! * jiroPattern.filter { it.key == i }.map { it.value }.sum()
        loseCount += taroPatttern[i]!! * jiroPattern.filter { it.key  >i }.map { it.value }.sum()
    }
    var ans = winCount.toDouble() / (winCount + loseCount + drawCount)
    println(ans)
}

val ikasamaDic = mutableMapOf<Int,MutableMap<Int, Long>>()

fun getAns(remain:Int):MutableMap<Int, Long> {
    if(remain == 1) {
        return (1..6).map { Pair(it, 1.toLong()) }.toMap().toMutableMap()
    }
    val ans = mutableMapOf<Int,Long>()
    val ret = getAns(remain - 1)
    for(i in (1..6)) {
        for (j in ret.keys) {
            ans[i+j]?.also {
                ans[i+j] = it + ret[j]!!
            }?: run {
                ans[i+j] = ret[j]!!
            }
        }
    }
    return ans
}

fun getIkasamaAns(remain:Int, ikasamaRemain:Int):MutableMap<Int, Long> {
    if(ikasamaRemain <= 0) {
        return getAns(remain)
    }
    if(remain == 1) {
        return (4..6).map { Pair(it, 2.toLong()) }.toMap().toMutableMap()
    }
    val ans = mutableMapOf<Int,Long>()
    val ret = getIkasamaAns(remain - 1, ikasamaRemain - 1)
    for(i in (1..6)) {
        for (j in ret.keys) {
            val key = (((i-1)%3) + 4) + j
            ans[key]?.also {
                ans[key] = it + ret[j]!!
            }?: run {
                ans[key] = ret[j]!!
            }
        }
    }
    return ans
}
0