結果
| 問題 |
No.1835 Generalized Monty Hall Problem
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-07-21 08:39:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 1,000 ms |
| コード長 | 2,858 bytes |
| コンパイル時間 | 4,018 ms |
| コンパイル使用メモリ | 95,932 KB |
| 実行使用メモリ | 40,180 KB |
| 最終ジャッジ日時 | 2024-09-21 10:51:33 |
| 合計ジャッジ時間 | 4,830 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 11 |
ソースコード
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();
}
}
tenten