結果
問題 | No.1835 Generalized Monty Hall Problem |
ユーザー | yudedako |
提出日時 | 2022-02-21 23:15:51 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 900 ms / 1,000 ms |
コード長 | 2,186 bytes |
コンパイル時間 | 11,509 ms |
コンパイル使用メモリ | 272,500 KB |
実行使用メモリ | 63,340 KB |
最終ジャッジ日時 | 2024-06-30 01:58:39 |
合計ジャッジ時間 | 26,377 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 884 ms
63,208 KB |
testcase_01 | AC | 887 ms
63,264 KB |
testcase_02 | AC | 896 ms
63,144 KB |
testcase_03 | AC | 894 ms
63,244 KB |
testcase_04 | AC | 900 ms
63,276 KB |
testcase_05 | AC | 898 ms
63,124 KB |
testcase_06 | AC | 884 ms
63,068 KB |
testcase_07 | AC | 887 ms
63,300 KB |
testcase_08 | AC | 879 ms
63,180 KB |
testcase_09 | AC | 887 ms
63,236 KB |
testcase_10 | AC | 887 ms
63,216 KB |
testcase_11 | AC | 891 ms
63,296 KB |
testcase_12 | AC | 885 ms
63,340 KB |
testcase_13 | AC | 892 ms
63,156 KB |
testcase_14 | AC | 886 ms
63,248 KB |
ソースコード
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 type Integer = BigInt class Rational private (private var num: Integer, private var den: Integer): def numerator: Integer = num def denominator: Integer = 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: Integer, den: Integer): (Integer, Integer) = val g = gcd(num.abs, den.abs) val sign = num.sign * den.sign (num.abs * sign / g, den.abs / g) def from(num: Integer, den: Integer): Rational = val (n, d) = normalize(num, den) Rational(n, d) def gcd(a: Integer, b: Integer): Integer = a.gcd(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}")