結果
問題 | No.1835 Generalized Monty Hall Problem |
ユーザー | tenten |
提出日時 | 2023-07-21 08:35:07 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,701 bytes |
コンパイル時間 | 2,559 ms |
コンパイル使用メモリ | 91,240 KB |
実行使用メモリ | 53,524 KB |
最終ジャッジ日時 | 2024-09-21 10:46:42 |
合計ジャッジ時間 | 4,676 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
51,164 KB |
testcase_01 | AC | 80 ms
51,080 KB |
testcase_02 | AC | 81 ms
51,628 KB |
testcase_03 | AC | 84 ms
53,104 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 | 83 ms
51,384 KB |
testcase_14 | AC | 80 ms
50,808 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); Bunsu x = new Bunsu(m, n).multiply(new Bunsu(m - 1, n - k - 1)).add(new Bunsu(n - m, n).multiply(new Bunsu(m, n - k - 1))); System.out.println(x); } static class Bunsu { long child; long mother; public Bunsu(long child, long mother) { this.child = child; this.mother = mother; init(); } private void init() { if (child == 0) { mother = 1; return; } long gcd = getGCD(child, mother); child /= gcd; mother /= gcd; } private long getGCD(long x, long y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } public Bunsu multiply(Bunsu x) { return new Bunsu(child * x.child, mother * x.mother); } public Bunsu add(Bunsu x) { return new Bunsu(child * x.mother + x.child * mother, mother * x.mother); } public String toString() { return child + " " + mother; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }