結果

問題 No.1835 Generalized Monty Hall Problem
ユーザー yudedakoyudedako
提出日時 2022-02-21 23:13:09
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 2,178 bytes
コンパイル時間 13,687 ms
コンパイル使用メモリ 253,128 KB
実行使用メモリ 63,588 KB
最終ジャッジ日時 2023-09-12 13:51:19
合計ジャッジ時間 29,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 939 ms
62,332 KB
testcase_01 AC 936 ms
62,260 KB
testcase_02 AC 936 ms
62,252 KB
testcase_03 AC 931 ms
62,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 911 ms
62,132 KB
testcase_14 AC 921 ms
63,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*
import scala.reflect.{ClassTag, classTag}
import scala.util.*

import scala.annotation.tailrec
class Rational private (private var num: Long, private var den: Long):
  def numerator: Long = num
  def denominator: Long = den
  def +(other: Rational): Rational = Rational.from(num * other.den + den * other.num, den * other.den)
  def -(other: Rational): Rational = Rational.from(num * other.den - den * other.num, den * other.den)
  def *(other: Rational): Rational = Rational.from(num * other.num, den * other.den)
  def /(other: Rational): Rational = Rational.from(num * other.den, den * other.num)
  def +=(other: Rational) =
    val (n, d) = Rational.normalize(num * other.den + den * other.num, den * other.den)
    num = n
    den = d
  def -=(other: Rational) =
    val (n, d) = Rational.normalize(num * other.den - den * other.num, den * other.den)
    num = n
    den = d
  def *=(other: Rational) =
    val (n, d) = Rational.normalize(num * other.num, den * other.den)
    num = n
    den = d
  def /=(other: Rational) =
    val (n, d) = Rational.normalize(num * other.den, den * other.num)
    num = n
    den = d

object Rational:
  given Ordering[Rational] with
    override def compare(x: Rational, y: Rational) = (x - y).num.compare(0)
  private inline def normalize(num: Long, den: Long): (Long, Long) =
    val g = gcd(num.abs, den.abs)
    val sign = num.sign * den.sign
    (num.abs * sign / g, den.abs / g)

  def from(num: Long, den: Long): Rational =
    val (n, d) = normalize(num, den)
    Rational(n, d)
  @tailrec
  def gcd(a: Long, b: Long): Long =
    b match
      case 0 => a
      case _ => gcd(b, a % b)

@main def main =
  import Rational.given_Ordering_Rational.mkOrderingOps
  val Array(n, m, k) = readLine.split(' ').map(_.toLong)
  val notMove = Rational.from(m, n)
  val move = Rational.from(m, n) * Rational.from(m - 1, n - k - 1) + Rational.from(n - m, n) * Rational.from(m, n - k - 1)
  val max = if notMove < move then move else notMove
  println(s"${max.numerator} ${max.denominator}")
0