結果

問題 No.955 ax^2+bx+c=0
ユーザー 37zigen37zigen
提出日時 2019-12-18 01:21:18
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,217 bytes
コンパイル時間 2,903 ms
コンパイル使用メモリ 76,140 KB
実行使用メモリ 58,100 KB
最終ジャッジ日時 2023-09-21 05:40:07
合計ジャッジ時間 23,219 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
55,752 KB
testcase_01 AC 128 ms
55,632 KB
testcase_02 AC 128 ms
55,536 KB
testcase_03 AC 130 ms
55,520 KB
testcase_04 AC 130 ms
56,144 KB
testcase_05 AC 130 ms
53,592 KB
testcase_06 AC 127 ms
55,896 KB
testcase_07 AC 127 ms
55,356 KB
testcase_08 AC 128 ms
55,740 KB
testcase_09 AC 125 ms
55,712 KB
testcase_10 AC 132 ms
55,696 KB
testcase_11 AC 128 ms
55,444 KB
testcase_12 AC 128 ms
55,652 KB
testcase_13 AC 126 ms
55,704 KB
testcase_14 AC 127 ms
55,552 KB
testcase_15 AC 125 ms
55,596 KB
testcase_16 AC 128 ms
55,672 KB
testcase_17 AC 127 ms
55,976 KB
testcase_18 AC 129 ms
55,680 KB
testcase_19 AC 132 ms
55,656 KB
testcase_20 AC 130 ms
55,644 KB
testcase_21 AC 128 ms
55,820 KB
testcase_22 AC 128 ms
55,452 KB
testcase_23 AC 132 ms
55,952 KB
testcase_24 AC 135 ms
55,748 KB
testcase_25 AC 131 ms
55,672 KB
testcase_26 AC 128 ms
55,624 KB
testcase_27 AC 129 ms
55,736 KB
testcase_28 AC 128 ms
55,548 KB
testcase_29 AC 129 ms
55,868 KB
testcase_30 AC 130 ms
55,760 KB
testcase_31 AC 129 ms
55,568 KB
testcase_32 AC 127 ms
55,716 KB
testcase_33 AC 130 ms
55,560 KB
testcase_34 AC 131 ms
55,660 KB
testcase_35 AC 133 ms
55,992 KB
testcase_36 AC 134 ms
55,768 KB
testcase_37 AC 129 ms
55,800 KB
testcase_38 AC 133 ms
57,780 KB
testcase_39 AC 130 ms
55,760 KB
testcase_40 AC 135 ms
55,772 KB
testcase_41 AC 131 ms
56,068 KB
testcase_42 AC 131 ms
55,536 KB
testcase_43 AC 130 ms
55,684 KB
testcase_44 AC 129 ms
56,072 KB
testcase_45 AC 132 ms
55,492 KB
testcase_46 AC 130 ms
55,972 KB
testcase_47 AC 135 ms
56,100 KB
testcase_48 AC 131 ms
55,652 KB
testcase_49 AC 134 ms
58,004 KB
testcase_50 AC 131 ms
55,992 KB
testcase_51 AC 131 ms
55,560 KB
testcase_52 AC 132 ms
55,748 KB
testcase_53 AC 131 ms
55,768 KB
testcase_54 AC 132 ms
55,808 KB
testcase_55 AC 132 ms
56,080 KB
testcase_56 AC 129 ms
55,604 KB
testcase_57 AC 132 ms
55,492 KB
testcase_58 AC 130 ms
55,976 KB
testcase_59 AC 132 ms
55,852 KB
testcase_60 AC 130 ms
55,652 KB
testcase_61 AC 132 ms
55,452 KB
testcase_62 AC 134 ms
56,036 KB
testcase_63 AC 133 ms
56,028 KB
testcase_64 AC 129 ms
55,320 KB
testcase_65 AC 133 ms
55,808 KB
testcase_66 AC 133 ms
55,568 KB
testcase_67 AC 132 ms
55,808 KB
testcase_68 AC 130 ms
55,748 KB
testcase_69 AC 134 ms
55,964 KB
testcase_70 AC 131 ms
55,792 KB
testcase_71 AC 127 ms
55,680 KB
testcase_72 AC 126 ms
55,664 KB
testcase_73 AC 131 ms
55,492 KB
testcase_74 AC 132 ms
55,844 KB
testcase_75 AC 130 ms
55,748 KB
testcase_76 AC 128 ms
55,976 KB
testcase_77 AC 131 ms
55,588 KB
testcase_78 AC 130 ms
55,576 KB
testcase_79 AC 132 ms
55,900 KB
testcase_80 AC 126 ms
56,052 KB
testcase_81 AC 131 ms
56,152 KB
testcase_82 AC 127 ms
55,960 KB
testcase_83 AC 129 ms
55,604 KB
testcase_84 AC 129 ms
55,856 KB
testcase_85 AC 129 ms
55,464 KB
testcase_86 AC 128 ms
55,756 KB
testcase_87 AC 131 ms
56,020 KB
testcase_88 AC 133 ms
55,740 KB
testcase_89 AC 130 ms
55,852 KB
testcase_90 AC 136 ms
55,912 KB
testcase_91 AC 135 ms
55,972 KB
testcase_92 AC 135 ms
55,752 KB
testcase_93 AC 136 ms
55,648 KB
testcase_94 AC 135 ms
55,372 KB
testcase_95 AC 128 ms
55,824 KB
testcase_96 AC 130 ms
55,764 KB
testcase_97 AC 131 ms
55,464 KB
testcase_98 AC 130 ms
55,624 KB
testcase_99 AC 133 ms
55,548 KB
testcase_100 AC 134 ms
57,516 KB
testcase_101 AC 133 ms
55,876 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 AC 132 ms
55,792 KB
testcase_123 AC 135 ms
56,128 KB
testcase_124 AC 133 ms
55,932 KB
権限があれば一括ダウンロードができます

ソースコード

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+c=0
			// b!=0
			System.out.println(1);
			System.out.println(c / b);
		} 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) {
					double tmp=x1;
					x1 = x2;
					x2 = tmp;
				}
				System.out.println(x1);
				System.out.println(x2);
			}

		}
	}

	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