結果

問題 No.955 ax^2+bx+c=0
ユーザー ks2mks2m
提出日時 2019-12-18 00:54:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,911 bytes
コンパイル時間 5,288 ms
コンパイル使用メモリ 79,688 KB
実行使用メモリ 55,676 KB
最終ジャッジ日時 2023-10-19 02:02:45
合計ジャッジ時間 13,627 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
54,640 KB
testcase_01 AC 56 ms
52,516 KB
testcase_02 AC 57 ms
53,528 KB
testcase_03 AC 56 ms
53,520 KB
testcase_04 AC 55 ms
53,536 KB
testcase_05 AC 55 ms
53,528 KB
testcase_06 AC 55 ms
53,520 KB
testcase_07 AC 56 ms
53,468 KB
testcase_08 AC 55 ms
52,436 KB
testcase_09 AC 55 ms
53,536 KB
testcase_10 AC 55 ms
52,420 KB
testcase_11 AC 56 ms
53,528 KB
testcase_12 AC 57 ms
53,520 KB
testcase_13 AC 57 ms
52,512 KB
testcase_14 AC 56 ms
53,524 KB
testcase_15 AC 55 ms
53,472 KB
testcase_16 AC 55 ms
53,520 KB
testcase_17 AC 55 ms
53,532 KB
testcase_18 AC 55 ms
53,472 KB
testcase_19 AC 57 ms
52,432 KB
testcase_20 AC 56 ms
53,524 KB
testcase_21 AC 56 ms
53,528 KB
testcase_22 AC 55 ms
53,536 KB
testcase_23 AC 55 ms
53,532 KB
testcase_24 AC 56 ms
53,536 KB
testcase_25 AC 57 ms
53,528 KB
testcase_26 AC 55 ms
52,404 KB
testcase_27 AC 56 ms
53,540 KB
testcase_28 AC 55 ms
53,532 KB
testcase_29 AC 56 ms
53,524 KB
testcase_30 AC 56 ms
53,536 KB
testcase_31 AC 56 ms
53,532 KB
testcase_32 AC 56 ms
53,528 KB
testcase_33 AC 56 ms
53,528 KB
testcase_34 AC 79 ms
53,700 KB
testcase_35 AC 76 ms
54,696 KB
testcase_36 AC 78 ms
54,696 KB
testcase_37 AC 72 ms
54,672 KB
testcase_38 AC 70 ms
54,656 KB
testcase_39 AC 68 ms
54,180 KB
testcase_40 AC 77 ms
54,940 KB
testcase_41 AC 77 ms
54,648 KB
testcase_42 AC 75 ms
54,764 KB
testcase_43 AC 72 ms
54,188 KB
testcase_44 AC 68 ms
54,092 KB
testcase_45 AC 66 ms
54,112 KB
testcase_46 AC 69 ms
54,648 KB
testcase_47 AC 67 ms
54,668 KB
testcase_48 AC 65 ms
54,620 KB
testcase_49 AC 75 ms
54,708 KB
testcase_50 AC 79 ms
55,676 KB
testcase_51 AC 74 ms
54,776 KB
testcase_52 AC 70 ms
54,096 KB
testcase_53 AC 69 ms
54,652 KB
testcase_54 AC 68 ms
54,572 KB
testcase_55 AC 78 ms
54,612 KB
testcase_56 AC 78 ms
54,752 KB
testcase_57 AC 77 ms
54,744 KB
testcase_58 AC 69 ms
54,648 KB
testcase_59 AC 67 ms
54,108 KB
testcase_60 AC 56 ms
53,520 KB
testcase_61 AC 55 ms
53,516 KB
testcase_62 AC 72 ms
54,688 KB
testcase_63 AC 73 ms
54,656 KB
testcase_64 AC 56 ms
53,532 KB
testcase_65 AC 73 ms
54,188 KB
testcase_66 AC 57 ms
53,540 KB
testcase_67 AC 72 ms
54,180 KB
testcase_68 AC 56 ms
53,532 KB
testcase_69 AC 72 ms
54,648 KB
testcase_70 AC 73 ms
54,084 KB
testcase_71 AC 57 ms
53,520 KB
testcase_72 AC 57 ms
53,528 KB
testcase_73 AC 71 ms
54,568 KB
testcase_74 AC 74 ms
54,092 KB
testcase_75 AC 57 ms
53,516 KB
testcase_76 AC 56 ms
53,524 KB
testcase_77 AC 71 ms
53,336 KB
testcase_78 AC 72 ms
54,636 KB
testcase_79 AC 72 ms
54,104 KB
testcase_80 AC 56 ms
53,536 KB
testcase_81 AC 71 ms
54,092 KB
testcase_82 AC 56 ms
53,528 KB
testcase_83 AC 58 ms
52,464 KB
testcase_84 AC 57 ms
52,464 KB
testcase_85 AC 58 ms
53,552 KB
testcase_86 AC 57 ms
53,556 KB
testcase_87 AC 56 ms
53,532 KB
testcase_88 AC 57 ms
53,532 KB
testcase_89 AC 56 ms
53,528 KB
testcase_90 AC 56 ms
53,560 KB
testcase_91 AC 55 ms
53,560 KB
testcase_92 AC 57 ms
53,536 KB
testcase_93 AC 56 ms
53,520 KB
testcase_94 AC 58 ms
53,556 KB
testcase_95 AC 56 ms
53,564 KB
testcase_96 AC 56 ms
53,548 KB
testcase_97 AC 55 ms
53,556 KB
testcase_98 AC 58 ms
53,556 KB
testcase_99 AC 56 ms
53,560 KB
testcase_100 AC 55 ms
53,516 KB
testcase_101 AC 56 ms
53,560 KB
testcase_102 AC 56 ms
53,556 KB
testcase_103 AC 56 ms
53,548 KB
testcase_104 AC 57 ms
53,548 KB
testcase_105 AC 56 ms
53,544 KB
testcase_106 AC 56 ms
53,556 KB
testcase_107 AC 57 ms
53,556 KB
testcase_108 AC 56 ms
53,552 KB
testcase_109 AC 58 ms
53,576 KB
testcase_110 AC 56 ms
53,548 KB
testcase_111 AC 57 ms
51,504 KB
testcase_112 AC 56 ms
53,552 KB
testcase_113 AC 56 ms
53,560 KB
testcase_114 AC 56 ms
53,568 KB
testcase_115 AC 56 ms
53,548 KB
testcase_116 AC 56 ms
52,460 KB
testcase_117 AC 57 ms
52,548 KB
testcase_118 AC 56 ms
53,564 KB
testcase_119 AC 56 ms
53,560 KB
testcase_120 AC 57 ms
53,564 KB
testcase_121 AC 58 ms
51,508 KB
testcase_122 AC 71 ms
54,632 KB
testcase_123 AC 69 ms
54,680 KB
testcase_124 AC 70 ms
54,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		long a = Integer.parseInt(sa[0]);
		long b = Integer.parseInt(sa[1]);
		long c = Integer.parseInt(sa[2]);
		br.close();

		if (a == 0) {
			if (b == 0) {
				if (c == 0) {
					System.out.println(-1);
				} else {
					System.out.println(0);
				}
			} else {
				System.out.println(1);
				System.out.println((double) -c / b);
			}
		} else if (b * b == 4 * a * c) {
			System.out.println(1);
			System.out.println((double) -b / 2 / a);
		} else if (b * b > 4 * a * c) {
			long d = b * b - 4 * a * c;
			BigDecimal bd = BigDecimal.valueOf(d);
			long e = (long) Math.sqrt(d);
			if (e * e > d) {
				e--;
			}
			BigDecimal sq = BigDecimal.valueOf(e);
			StringBuilder sb = new StringBuilder("0.");
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 10; j++) {
					BigDecimal v = new BigDecimal(sb.toString() + "1");
					BigDecimal tmp = sq.add(v);
					tmp = tmp.multiply(tmp);
					if (tmp.compareTo(bd) > 0) {
						break;
					}
					sq = sq.add(v);
				}
				sb.append("0");
			}
			System.out.println(2);
			BigDecimal ba = BigDecimal.valueOf(a);
			BigDecimal two = BigDecimal.valueOf(2);
			BigDecimal mb = BigDecimal.valueOf(b).negate();
			BigDecimal ans1 = mb.subtract(sq).divide(two).divide(ba, 20, BigDecimal.ROUND_HALF_UP);
			BigDecimal ans2 = mb.add(sq).divide(two).divide(ba, 20, BigDecimal.ROUND_HALF_UP);
			if (ans1.compareTo(ans2) < 0) {
				System.out.println(ans1.toPlainString());
				System.out.println(ans2.toPlainString());
			} else {
				System.out.println(ans2.toPlainString());
				System.out.println(ans1.toPlainString());
			}
		} else {
			System.out.println(0);
		}
	}
}
0