結果

問題 No.1835 Generalized Monty Hall Problem
ユーザー tentententen
提出日時 2023-07-21 08:39:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 99 ms / 1,000 ms
コード長 2,858 bytes
コンパイル時間 2,728 ms
コンパイル使用メモリ 91,400 KB
実行使用メモリ 56,180 KB
最終ジャッジ日時 2023-10-21 09:46:45
合計ジャッジ時間 4,993 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
54,428 KB
testcase_01 AC 84 ms
54,544 KB
testcase_02 AC 98 ms
55,044 KB
testcase_03 AC 90 ms
55,992 KB
testcase_04 AC 98 ms
55,996 KB
testcase_05 AC 86 ms
54,408 KB
testcase_06 AC 89 ms
56,180 KB
testcase_07 AC 89 ms
54,916 KB
testcase_08 AC 86 ms
54,516 KB
testcase_09 AC 89 ms
54,476 KB
testcase_10 AC 86 ms
54,384 KB
testcase_11 AC 86 ms
54,408 KB
testcase_12 AC 86 ms
54,384 KB
testcase_13 AC 99 ms
55,836 KB
testcase_14 AC 85 ms
54,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
            }
        }
        
        private long getLCM(long x, long y) {
            return x / getGCD(x, y) * y;
        }
        
        public Bunsu multiply(Bunsu x) {
            return new Bunsu(child * x.child, mother * x.mother);
        }
        
        public Bunsu add(Bunsu x) {
            long lcm = getLCM(mother, x.mother);
            return new Bunsu(child * (lcm / mother) + x.child * (lcm / x.mother), lcm);
        }
        
        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();
    }
    
}
0