結果

問題 No.955 ax^2+bx+c=0
ユーザー ks2mks2m
提出日時 2019-12-18 00:51:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 2,955 ms
コンパイル使用メモリ 76,984 KB
実行使用メモリ 52,180 KB
最終ジャッジ日時 2023-09-21 05:31:06
合計ジャッジ時間 12,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
50,244 KB
testcase_01 AC 45 ms
49,512 KB
testcase_02 AC 45 ms
49,180 KB
testcase_03 AC 45 ms
49,148 KB
testcase_04 AC 45 ms
49,388 KB
testcase_05 AC 45 ms
49,396 KB
testcase_06 AC 45 ms
49,396 KB
testcase_07 AC 45 ms
49,260 KB
testcase_08 AC 45 ms
49,316 KB
testcase_09 AC 44 ms
49,148 KB
testcase_10 AC 44 ms
49,400 KB
testcase_11 AC 45 ms
49,456 KB
testcase_12 AC 45 ms
49,268 KB
testcase_13 AC 44 ms
49,388 KB
testcase_14 AC 46 ms
49,268 KB
testcase_15 AC 45 ms
49,400 KB
testcase_16 AC 45 ms
49,268 KB
testcase_17 AC 45 ms
49,668 KB
testcase_18 AC 45 ms
49,408 KB
testcase_19 AC 46 ms
49,772 KB
testcase_20 AC 45 ms
49,400 KB
testcase_21 AC 45 ms
49,268 KB
testcase_22 AC 45 ms
49,492 KB
testcase_23 AC 45 ms
49,364 KB
testcase_24 AC 45 ms
49,220 KB
testcase_25 AC 45 ms
49,400 KB
testcase_26 AC 45 ms
49,584 KB
testcase_27 AC 45 ms
49,392 KB
testcase_28 AC 46 ms
49,616 KB
testcase_29 AC 49 ms
49,876 KB
testcase_30 AC 46 ms
49,224 KB
testcase_31 AC 45 ms
49,180 KB
testcase_32 AC 46 ms
49,392 KB
testcase_33 AC 46 ms
49,288 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 63 ms
50,288 KB
testcase_38 AC 57 ms
50,312 KB
testcase_39 AC 57 ms
50,288 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 62 ms
50,416 KB
testcase_44 AC 58 ms
50,284 KB
testcase_45 AC 58 ms
50,308 KB
testcase_46 AC 65 ms
50,368 KB
testcase_47 AC 59 ms
50,316 KB
testcase_48 AC 59 ms
50,352 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 64 ms
50,700 KB
testcase_53 AC 58 ms
50,280 KB
testcase_54 AC 63 ms
50,364 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 59 ms
50,356 KB
testcase_59 AC 59 ms
50,376 KB
testcase_60 AC 45 ms
49,224 KB
testcase_61 AC 46 ms
49,180 KB
testcase_62 AC 64 ms
50,484 KB
testcase_63 AC 64 ms
50,572 KB
testcase_64 AC 46 ms
49,156 KB
testcase_65 AC 64 ms
50,396 KB
testcase_66 AC 46 ms
49,516 KB
testcase_67 AC 63 ms
50,356 KB
testcase_68 AC 46 ms
49,272 KB
testcase_69 AC 63 ms
50,352 KB
testcase_70 AC 61 ms
50,716 KB
testcase_71 AC 46 ms
49,236 KB
testcase_72 AC 46 ms
49,868 KB
testcase_73 AC 66 ms
50,244 KB
testcase_74 AC 66 ms
50,380 KB
testcase_75 AC 47 ms
49,280 KB
testcase_76 AC 46 ms
49,880 KB
testcase_77 AC 62 ms
50,384 KB
testcase_78 AC 66 ms
50,520 KB
testcase_79 AC 63 ms
50,304 KB
testcase_80 AC 45 ms
49,136 KB
testcase_81 AC 61 ms
50,472 KB
testcase_82 AC 45 ms
49,224 KB
testcase_83 AC 46 ms
49,408 KB
testcase_84 AC 45 ms
49,396 KB
testcase_85 AC 46 ms
49,232 KB
testcase_86 AC 45 ms
49,236 KB
testcase_87 AC 45 ms
49,264 KB
testcase_88 AC 44 ms
49,272 KB
testcase_89 AC 44 ms
49,548 KB
testcase_90 AC 46 ms
49,464 KB
testcase_91 AC 45 ms
49,288 KB
testcase_92 AC 46 ms
49,580 KB
testcase_93 AC 46 ms
49,584 KB
testcase_94 AC 47 ms
49,540 KB
testcase_95 AC 48 ms
49,396 KB
testcase_96 AC 45 ms
47,264 KB
testcase_97 AC 45 ms
49,504 KB
testcase_98 AC 46 ms
49,468 KB
testcase_99 AC 45 ms
49,276 KB
testcase_100 AC 46 ms
49,708 KB
testcase_101 AC 45 ms
49,280 KB
testcase_102 AC 45 ms
49,288 KB
testcase_103 AC 45 ms
49,224 KB
testcase_104 AC 46 ms
49,444 KB
testcase_105 AC 46 ms
49,284 KB
testcase_106 AC 46 ms
49,160 KB
testcase_107 AC 46 ms
49,276 KB
testcase_108 AC 46 ms
49,152 KB
testcase_109 AC 45 ms
49,332 KB
testcase_110 AC 46 ms
49,768 KB
testcase_111 AC 46 ms
49,344 KB
testcase_112 AC 46 ms
49,420 KB
testcase_113 AC 46 ms
49,780 KB
testcase_114 AC 46 ms
49,424 KB
testcase_115 AC 46 ms
49,228 KB
testcase_116 AC 46 ms
49,472 KB
testcase_117 AC 46 ms
49,536 KB
testcase_118 AC 46 ms
49,160 KB
testcase_119 AC 46 ms
49,304 KB
testcase_120 AC 45 ms
49,540 KB
testcase_121 AC 45 ms
49,532 KB
testcase_122 AC 59 ms
48,620 KB
testcase_123 AC 58 ms
48,588 KB
testcase_124 AC 59 ms
50,372 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);
			BigDecimal sq = BigDecimal.valueOf((long) Math.sqrt(d));
			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