結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー pekempeypekempey
提出日時 2015-06-20 13:47:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 2,034 bytes
コンパイル時間 2,668 ms
コンパイル使用メモリ 81,504 KB
実行使用メモリ 57,300 KB
最終ジャッジ日時 2023-09-21 22:02:46
合計ジャッジ時間 11,218 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
56,964 KB
testcase_01 AC 145 ms
56,916 KB
testcase_02 AC 145 ms
57,068 KB
testcase_03 AC 145 ms
57,028 KB
testcase_04 AC 145 ms
56,672 KB
testcase_05 AC 147 ms
56,764 KB
testcase_06 AC 148 ms
57,068 KB
testcase_07 AC 149 ms
56,976 KB
testcase_08 AC 150 ms
56,984 KB
testcase_09 AC 153 ms
56,608 KB
testcase_10 AC 149 ms
56,996 KB
testcase_11 AC 151 ms
57,032 KB
testcase_12 AC 153 ms
57,168 KB
testcase_13 AC 148 ms
56,788 KB
testcase_14 AC 152 ms
56,888 KB
testcase_15 AC 150 ms
56,892 KB
testcase_16 AC 150 ms
56,976 KB
testcase_17 AC 150 ms
57,236 KB
testcase_18 AC 150 ms
56,824 KB
testcase_19 AC 149 ms
56,980 KB
testcase_20 AC 149 ms
57,004 KB
testcase_21 AC 149 ms
56,876 KB
testcase_22 AC 151 ms
56,832 KB
testcase_23 AC 153 ms
57,080 KB
testcase_24 AC 151 ms
57,184 KB
testcase_25 AC 152 ms
57,144 KB
testcase_26 AC 149 ms
56,940 KB
testcase_27 AC 149 ms
56,868 KB
testcase_28 AC 149 ms
56,612 KB
testcase_29 AC 149 ms
56,912 KB
testcase_30 AC 147 ms
56,932 KB
testcase_31 AC 147 ms
57,248 KB
testcase_32 AC 147 ms
56,828 KB
testcase_33 AC 148 ms
56,988 KB
testcase_34 AC 150 ms
57,300 KB
testcase_35 AC 149 ms
56,896 KB
testcase_36 AC 150 ms
56,916 KB
testcase_37 AC 149 ms
57,200 KB
testcase_38 AC 152 ms
56,992 KB
testcase_39 AC 151 ms
57,048 KB
testcase_40 AC 151 ms
57,236 KB
testcase_41 AC 149 ms
56,832 KB
testcase_42 AC 151 ms
56,852 KB
testcase_43 AC 150 ms
57,008 KB
testcase_44 AC 151 ms
56,628 KB
testcase_45 AC 151 ms
57,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);

        int[] t = new int[3];

        for (int i = 0; i < 3; i++) {
            t[i] = cin.nextInt();
        }

        Arrays.sort(t);

        BigInteger[] T = new BigInteger[3];
        T[0] = BigInteger.valueOf(t[0]);
        T[1] = BigInteger.valueOf(t[1]);
        T[2] = BigInteger.valueOf(t[2]);

        BigInteger[] W = new BigInteger[6];

        W[0] = T[0].add(T[1]);
        W[1] = T[1].add(T[2]);
        W[2] = T[2].add(T[0]);
        W[3] = T[1].subtract(T[0]);
        W[4] = T[2].subtract(T[1]);
        W[5] = T[2].subtract(T[0]);

        BigInteger L = W[0];

        for (int i = 0; i < 6; i++) {
            L = lcm(L, W[i]);
        }

        BigInteger[] S = new BigInteger[6];

        S[0] = L.multiply(T[0]).multiply(T[1]).divide(W[0]);
        S[1] = L.multiply(T[1]).multiply(T[2]).divide(W[1]);
        S[2] = L.multiply(T[2]).multiply(T[0]).divide(W[2]);
        S[3] = L.multiply(T[0]).multiply(T[1]).divide(W[3]);
        S[4] = L.multiply(T[1]).multiply(T[2]).divide(W[4]);
        S[5] = L.multiply(T[2]).multiply(T[0]).divide(W[5]);

        BigInteger[] n = new BigInteger[8];

        n[0] = lcm(S[0], S[1], S[2]);
        n[1] = lcm(S[3], S[1], S[2]);
        n[2] = lcm(S[0], S[4], S[2]);
        n[3] = lcm(S[3], S[4], S[2]);
        n[4] = lcm(S[0], S[1], S[5]);
        n[5] = lcm(S[3], S[1], S[5]);
        n[6] = lcm(S[0], S[4], S[5]);
        n[7] = lcm(S[3], S[4], S[5]);

        BigInteger x = n[0];

        for (int i = 0; i < 8; i++) {
            x = x.min(n[i]);
        }

        BigInteger g = x.gcd(L);

        x = x.divide(g);
        L = L.divide(g);

        System.out.println(x + "/" + L);
    }

    static BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(a.gcd(b));
    }

    static BigInteger lcm(BigInteger a, BigInteger b, BigInteger c) {
        return lcm(a, lcm(b, c));
    }
}
0