結果

問題 No.1688 Veterinarian
ユーザー 👑 箱
提出日時 2021-09-24 23:07:36
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 1,673 ms / 3,000 ms
コード長 2,675 bytes
コンパイル時間 17,640 ms
コンパイル使用メモリ 426,648 KB
実行使用メモリ 254,208 KB
最終ジャッジ日時 2023-09-18 22:13:08
合計ジャッジ時間 32,980 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 629 ms
252,328 KB
testcase_01 AC 630 ms
251,840 KB
testcase_02 AC 634 ms
253,256 KB
testcase_03 AC 637 ms
252,220 KB
testcase_04 AC 630 ms
252,920 KB
testcase_05 AC 634 ms
252,324 KB
testcase_06 AC 628 ms
252,256 KB
testcase_07 AC 799 ms
253,020 KB
testcase_08 AC 1,673 ms
252,024 KB
testcase_09 AC 1,603 ms
254,208 KB
testcase_10 AC 660 ms
251,996 KB
testcase_11 AC 693 ms
252,152 KB
testcase_12 AC 645 ms
252,792 KB
testcase_13 AC 640 ms
251,784 KB
testcase_14 AC 632 ms
253,236 KB
testcase_15 AC 655 ms
252,012 KB
testcase_16 AC 663 ms
253,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val a = nextInt()
    val b = nextInt()
    val c = nextInt()
    val n = nextInt()
    val dpa = Array(51) { Array(51) { Array(51) { DoubleArray(51) { 0.0 } } } }
    val dpb = Array(51) { Array(51) { Array(51) { DoubleArray(51) { 0.0 } } } }
    val dpc = Array(51) { Array(51) { Array(51) { DoubleArray(51) { 0.0 } } } }
    for (i in 1..n) {
        for (x in 0..a) {
            for (y in 0..b) {
                for (z in 0..c) {
                    if (x + y + z <= 1) continue
                    val pa = x * (x - 1.0) / (x + y + z) / (x + y + z - 1.0)
                    val pb = y * (y - 1.0) / (x + y + z) / (x + y + z - 1.0)
                    val pc = z * (z - 1.0) / (x + y + z) / (x + y + z - 1.0)
                    dpa[x][y][z][i] = (1 - pa - pb - pc) * dpa[x][y][z][i - 1]
                    dpb[x][y][z][i] = (1 - pa - pb - pc) * dpb[x][y][z][i - 1]
                    dpc[x][y][z][i] = (1 - pa - pb - pc) * dpc[x][y][z][i - 1]
                    if (x >= 1) {
                        dpa[x][y][z][i] += pa * (1 + dpa[x - 1][y][z][i - 1])
                        dpb[x][y][z][i] += pa * dpb[x - 1][y][z][i - 1]
                        dpc[x][y][z][i] += pa * dpc[x - 1][y][z][i - 1]
                    }
                    if (y >= 1) {
                        dpa[x][y][z][i] += pb * dpa[x][y - 1][z][i - 1]
                        dpb[x][y][z][i] += pb * (1 + dpb[x][y - 1][z][i - 1])
                        dpc[x][y][z][i] += pb * dpc[x][y - 1][z][i - 1]
                    }
                    if (z >= 1) {
                        dpa[x][y][z][i] += pc * dpa[x][y][z - 1][i - 1]
                        dpb[x][y][z][i] += pc * dpb[x][y][z - 1][i - 1]
                        dpc[x][y][z][i] += pc * (1 + dpc[x][y][z - 1][i - 1])
                    }
                }
            }
        }
    }
    println("${dpa[a][b][c][n]} ${dpb[a][b][c][n]} ${dpc[a][b][c][n]}")
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", 1.shl(26))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0