結果

問題 No.955 ax^2+bx+c=0
ユーザー 37zigen37zigen
提出日時 2019-12-18 01:10:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,268 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 76,380 KB
実行使用メモリ 58,136 KB
最終ジャッジ日時 2023-09-21 05:38:52
合計ジャッジ時間 24,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 133 ms
55,644 KB
testcase_02 AC 133 ms
55,628 KB
testcase_03 AC 139 ms
55,568 KB
testcase_04 AC 143 ms
55,396 KB
testcase_05 AC 135 ms
55,556 KB
testcase_06 AC 136 ms
55,420 KB
testcase_07 AC 146 ms
55,436 KB
testcase_08 AC 139 ms
53,800 KB
testcase_09 AC 128 ms
55,520 KB
testcase_10 AC 129 ms
55,616 KB
testcase_11 AC 128 ms
55,312 KB
testcase_12 AC 126 ms
55,644 KB
testcase_13 AC 127 ms
55,516 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 130 ms
55,532 KB
testcase_25 AC 128 ms
55,556 KB
testcase_26 AC 127 ms
55,528 KB
testcase_27 AC 128 ms
55,704 KB
testcase_28 AC 129 ms
53,712 KB
testcase_29 AC 134 ms
55,624 KB
testcase_30 AC 129 ms
53,752 KB
testcase_31 AC 128 ms
55,716 KB
testcase_32 AC 131 ms
55,692 KB
testcase_33 AC 132 ms
55,640 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 131 ms
55,536 KB
testcase_61 AC 127 ms
55,604 KB
testcase_62 WA -
testcase_63 WA -
testcase_64 AC 128 ms
55,560 KB
testcase_65 WA -
testcase_66 AC 127 ms
55,652 KB
testcase_67 WA -
testcase_68 AC 127 ms
56,076 KB
testcase_69 WA -
testcase_70 WA -
testcase_71 AC 132 ms
55,536 KB
testcase_72 AC 129 ms
55,504 KB
testcase_73 WA -
testcase_74 WA -
testcase_75 AC 131 ms
55,716 KB
testcase_76 AC 130 ms
55,692 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 AC 126 ms
56,000 KB
testcase_81 WA -
testcase_82 AC 128 ms
55,612 KB
testcase_83 AC 128 ms
55,544 KB
testcase_84 AC 129 ms
57,740 KB
testcase_85 AC 130 ms
55,772 KB
testcase_86 AC 130 ms
55,808 KB
testcase_87 AC 130 ms
55,584 KB
testcase_88 AC 130 ms
55,548 KB
testcase_89 AC 128 ms
55,548 KB
testcase_90 AC 132 ms
55,572 KB
testcase_91 AC 130 ms
55,612 KB
testcase_92 AC 129 ms
55,528 KB
testcase_93 AC 127 ms
55,708 KB
testcase_94 AC 129 ms
55,744 KB
testcase_95 AC 130 ms
55,640 KB
testcase_96 AC 128 ms
55,348 KB
testcase_97 AC 127 ms
55,568 KB
testcase_98 AC 129 ms
55,940 KB
testcase_99 AC 131 ms
55,368 KB
testcase_100 AC 130 ms
55,620 KB
testcase_101 AC 137 ms
55,444 KB
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 WA -
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 WA -
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
testcase_123 WA -
testcase_124 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;
import java.io.*;
import java.math.*;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
//		for (long a = -10; a <= 10; ++a)
//			for (long b = -10; b <= 10; ++b)
//				for (long c = -10; c <= 10; ++c)
		new Main().run(a, b, c);
	}

	void run(long a, long b, long c) {
		if (a < 0) {
			a *= -1;
			b *= -1;
			c *= -1;
		}
		if (a == 0 && b == 0 && c == 0) {// 0x^2+0x+0=0
			System.out.println(-1);
			return;
		} else if (a == 0 && b == 0 && c != 0) {// 0x^2+0x+c=0
			System.out.println(0);
		} else if (a == 0) {// 0x^2+bx+0=0
			System.out.println(1);
			System.out.println((double) c / a);
		} else if (a != 0) {
			BigDecimal DD = BigDecimal.valueOf(b * b)
					.subtract(BigDecimal.valueOf(4).multiply(BigDecimal.valueOf(a * c)));
			if (DD.compareTo(BigDecimal.ZERO) == -1) {
				System.out.println(0);
			} else if (DD.compareTo(BigDecimal.ZERO) == 0) {
				System.out.println(1);
				System.out.println((double) (-b) / (2 * a));
			} else {
				System.out.println(2);
				double x1 = BigDecimal.valueOf(-b).subtract(sqrt(DD, 50))
						.divide(BigDecimal.valueOf(2 * a), BigDecimal.ROUND_HALF_UP).doubleValue();
				double x2 = BigDecimal.valueOf(-b).add(sqrt(DD, 50))
						.divide(BigDecimal.valueOf(2 * a), BigDecimal.ROUND_HALF_UP).doubleValue();// (double)(-b+Math.sqrt(DD))/(2*a));
				if (x1 > x2)
					throw new AssertionError();
			}

		}
		// BigDecimal s2_50 = sqrt(new BigDecimal(2), 50);
		// System.out.println(s2_50);
		// System.out.println(s2_50.multiply(s2_50));
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static BigDecimal sqrt(BigDecimal a, int scale) {
		// とりあえずdoubleのsqrtを求める
		BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
		if (scale < 17)
			return x;

		BigDecimal b2 = new BigDecimal(2);
		for (int tempScale = 16; tempScale < scale; tempScale *= 2) {
			// x = x - (x * x - a) / (2 * x);
			x = x.subtract(x.multiply(x).subtract(a).divide(x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
		}
		return x;
	}
}
0