結果

問題 No.2555 Intriguing Triangle
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-12-02 00:03:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,170 bytes
コンパイル時間 3,664 ms
コンパイル使用メモリ 79,076 KB
実行使用メモリ 60,016 KB
最終ジャッジ日時 2023-12-02 00:03:09
合計ジャッジ時間 8,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,232 KB
testcase_01 AC 132 ms
57,984 KB
testcase_02 AC 132 ms
57,700 KB
testcase_03 AC 132 ms
57,956 KB
testcase_04 AC 133 ms
57,816 KB
testcase_05 AC 130 ms
57,824 KB
testcase_06 AC 130 ms
57,840 KB
testcase_07 AC 132 ms
58,088 KB
testcase_08 AC 141 ms
57,840 KB
testcase_09 AC 134 ms
57,960 KB
testcase_10 AC 140 ms
58,084 KB
testcase_11 AC 141 ms
57,956 KB
testcase_12 AC 146 ms
57,956 KB
testcase_13 AC 138 ms
58,084 KB
testcase_14 AC 139 ms
58,096 KB
testcase_15 AC 135 ms
57,968 KB
testcase_16 AC 143 ms
57,828 KB
testcase_17 AC 131 ms
57,964 KB
testcase_18 AC 131 ms
57,716 KB
testcase_19 AC 118 ms
56,800 KB
testcase_20 AC 142 ms
60,016 KB
testcase_21 AC 148 ms
60,004 KB
testcase_22 AC 130 ms
57,840 KB
testcase_23 WA -
testcase_24 AC 140 ms
56,384 KB
testcase_25 AC 132 ms
58,064 KB
testcase_26 AC 133 ms
57,852 KB
testcase_27 AC 136 ms
57,844 KB
testcase_28 AC 129 ms
58,220 KB
testcase_29 AC 133 ms
57,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Optional;
import java.util.Scanner;

public class Main {
    private static final double epsilon = 1e-9;

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int de = in.nextInt();
            int ab = in.nextInt();
            // d
            // e
            int ac = in.nextInt();

            boolean res = false;
            for (int bd = 1; bd <= 100; bd++) {
                for (int ec = 1; ec <= 100; ec++) {
                    if (!can_triangle(bd + de + ec, ab, ac)) {
                        continue;
                    }

                    Optional<Double> cos_dba = cosine_formula(ac, ab, bd + de + ec);
                    Optional<Double> cos_eca = cosine_formula(ab, ac, bd + de + ec);
                    if (cos_dba.isEmpty() || cos_eca.isEmpty()) {
                        continue;
                    }
                    double dba = Math.acos(cos_dba.get().doubleValue());
                    double eca = Math.acos(cos_eca.get().doubleValue());

                    Optional<Double> adxad = cosine_formula2(ab, bd, dba);
                    Optional<Double> aexae = cosine_formula2(ac, ec, eca);
                    if (adxad.isEmpty() || aexae.isEmpty()) {
                        continue;
                    }
                    double ad = Math.sqrt(adxad.get().doubleValue());
                    double ae = Math.sqrt(aexae.get().doubleValue());

                    if (!can_triangle(bd, ab, ad)) {
                        continue;
                    }
                    if (!can_triangle(ec, ac, ae)) {
                        continue;
                    }

                    Optional<Double> cos_bad = cosine_formula(bd, ab, ad);
                    Optional<Double> cos_cae = cosine_formula(ec, ac, ae);
                    if (cos_bad.isEmpty() || cos_cae.isEmpty()) {
                        continue;
                    }
                    double bad = Math.acos(cos_bad.get().doubleValue());
                    double cae = Math.acos(cos_cae.get().doubleValue());

                    if (Math.abs(bad - cae) < epsilon) {
                        res = true;
                    }
                }
            }
            System.out.println(res ? "Yes" : "No");
        }
    }

    private static final Optional<Double> cosine_formula(double a, double b, double c) {
        double cos = (b * b + c * c - a * a) / (2.0d * b * c);
        if (Math.abs(cos) > 1.0d) {
            return Optional.empty();
        }
        return Optional.of(cos);
    }

    private static final Optional<Double> cosine_formula2(double b, double c, double cab) {
        double axa = b * b + c * c - 2.0 * b * c * Math.cos(cab);
        if (axa < 0d) {
            return Optional.empty();
        }
        return Optional.of(axa);
    }

    private static final boolean can_triangle(double a, double b, double c) {
        return can_triangle0(a, b, c) || can_triangle0(c, a, b) || can_triangle0(b, c, a);
    }

    private static final boolean can_triangle0(double a, double b, double c) {
        return a > Math.max(b, c) && a < b + c;
    }
}
0