結果

問題 No.955 ax^2+bx+c=0
ユーザー 37zigen37zigen
提出日時 2019-12-18 00:50:35
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,851 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 85,976 KB
実行使用メモリ 58,552 KB
最終ジャッジ日時 2023-09-21 05:32:11
合計ジャッジ時間 21,313 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,748 KB
testcase_01 AC 122 ms
55,648 KB
testcase_02 AC 122 ms
55,692 KB
testcase_03 AC 121 ms
55,616 KB
testcase_04 AC 121 ms
55,616 KB
testcase_05 AC 121 ms
55,940 KB
testcase_06 AC 121 ms
55,444 KB
testcase_07 AC 122 ms
55,700 KB
testcase_08 AC 123 ms
55,504 KB
testcase_09 AC 123 ms
55,700 KB
testcase_10 AC 125 ms
55,620 KB
testcase_11 AC 122 ms
55,812 KB
testcase_12 AC 120 ms
55,440 KB
testcase_13 AC 121 ms
55,876 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 120 ms
55,656 KB
testcase_25 AC 123 ms
55,552 KB
testcase_26 AC 122 ms
55,352 KB
testcase_27 AC 122 ms
55,952 KB
testcase_28 AC 123 ms
55,872 KB
testcase_29 AC 122 ms
55,824 KB
testcase_30 AC 122 ms
55,348 KB
testcase_31 AC 122 ms
55,440 KB
testcase_32 AC 124 ms
55,676 KB
testcase_33 AC 122 ms
55,656 KB
testcase_34 AC 124 ms
55,632 KB
testcase_35 AC 125 ms
56,068 KB
testcase_36 AC 125 ms
56,152 KB
testcase_37 AC 124 ms
55,592 KB
testcase_38 AC 124 ms
55,760 KB
testcase_39 AC 125 ms
55,692 KB
testcase_40 AC 124 ms
55,732 KB
testcase_41 AC 125 ms
56,000 KB
testcase_42 AC 125 ms
55,616 KB
testcase_43 AC 123 ms
55,692 KB
testcase_44 AC 125 ms
55,736 KB
testcase_45 AC 124 ms
55,732 KB
testcase_46 AC 126 ms
56,072 KB
testcase_47 AC 125 ms
55,732 KB
testcase_48 AC 125 ms
55,748 KB
testcase_49 AC 125 ms
55,728 KB
testcase_50 AC 124 ms
56,272 KB
testcase_51 AC 123 ms
55,424 KB
testcase_52 AC 124 ms
56,024 KB
testcase_53 AC 123 ms
55,788 KB
testcase_54 AC 122 ms
55,908 KB
testcase_55 AC 125 ms
56,000 KB
testcase_56 AC 125 ms
55,732 KB
testcase_57 AC 126 ms
56,008 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 AC 122 ms
56,224 KB
testcase_61 AC 124 ms
55,616 KB
testcase_62 RE -
testcase_63 RE -
testcase_64 AC 121 ms
55,652 KB
testcase_65 RE -
testcase_66 AC 122 ms
55,708 KB
testcase_67 RE -
testcase_68 AC 124 ms
55,996 KB
testcase_69 RE -
testcase_70 RE -
testcase_71 AC 123 ms
55,412 KB
testcase_72 AC 124 ms
55,344 KB
testcase_73 RE -
testcase_74 RE -
testcase_75 AC 124 ms
55,708 KB
testcase_76 AC 122 ms
55,668 KB
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 AC 122 ms
56,232 KB
testcase_81 RE -
testcase_82 AC 123 ms
55,940 KB
testcase_83 AC 122 ms
55,872 KB
testcase_84 AC 122 ms
55,936 KB
testcase_85 AC 122 ms
55,820 KB
testcase_86 AC 122 ms
57,492 KB
testcase_87 AC 121 ms
55,340 KB
testcase_88 AC 121 ms
55,548 KB
testcase_89 AC 122 ms
55,340 KB
testcase_90 AC 122 ms
55,656 KB
testcase_91 AC 122 ms
55,672 KB
testcase_92 AC 123 ms
55,340 KB
testcase_93 AC 122 ms
55,612 KB
testcase_94 AC 122 ms
55,660 KB
testcase_95 AC 124 ms
55,336 KB
testcase_96 AC 122 ms
55,516 KB
testcase_97 AC 122 ms
55,348 KB
testcase_98 AC 121 ms
55,364 KB
testcase_99 AC 123 ms
55,876 KB
testcase_100 AC 121 ms
56,544 KB
testcase_101 AC 122 ms
55,920 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 126 ms
55,784 KB
testcase_123 AC 126 ms
55,632 KB
testcase_124 AC 126 ms
55,796 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) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		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) {
			long DD = b * b - 4 * a * c;
			if (DD < 0) {
				System.out.println(0);
			} else if (DD == 0) {
				System.out.println(1);
				System.out.println((double) (-b) / (2 * a));
			} else {
				System.out.println(2);
				System.out.println(
						BigDecimal.valueOf(-b).subtract(sqrt(new BigDecimal(DD), 50)).divide(BigDecimal.valueOf(2 * a)));// (double)(-b+Math.sqrt(DD))/(2*a));

				System.out.println(
						BigDecimal.valueOf(-b).add(sqrt(new BigDecimal(DD), 50)).divide(BigDecimal.valueOf(2 * a)));// (double)(-b+Math.sqrt(DD))/(2*a));
			}

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

	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