Avatar
@swift-5.4.3 // may cause "Cannot convert value of type 'Int' to expected argument type 'Builtin.FPIEEE64'" import Foundation let (N, M, K) = {() -> (Int, Int, Int) in let v = readLine()!.split(separator:" ").map{Int($0)!} return (v[0], v[1], v[2]) }() guard N - M >= K else { print(1.0) exit(0) } let b: [Double] = stride(from: N, through: N - K + 2, by: -1) .map({ i -> Double in Double(i)}) .map({ e -> Double in Double(e - 1 - M) / e }) let hazure = b.reduce(1.0) { (partialResult: inout Double, v: Double) -> Double in partialResult * v } let atari: Double = Double(M) / Double(N - K + 1) print(hazure * atari)