結果

問題 No.955 ax^2+bx+c=0
ユーザー agataYMGTagataYMGT
提出日時 2019-12-28 11:13:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 4,026 ms
コンパイル使用メモリ 78,832 KB
実行使用メモリ 42,348 KB
最終ジャッジ日時 2024-04-19 14:50:36
合計ジャッジ時間 20,144 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
41,732 KB
testcase_01 AC 118 ms
42,076 KB
testcase_02 AC 121 ms
41,728 KB
testcase_03 AC 114 ms
41,676 KB
testcase_04 AC 119 ms
41,444 KB
testcase_05 AC 119 ms
41,752 KB
testcase_06 AC 111 ms
41,940 KB
testcase_07 AC 117 ms
41,452 KB
testcase_08 AC 105 ms
41,812 KB
testcase_09 AC 115 ms
41,544 KB
testcase_10 AC 105 ms
41,808 KB
testcase_11 AC 105 ms
41,724 KB
testcase_12 AC 124 ms
41,816 KB
testcase_13 AC 123 ms
41,836 KB
testcase_14 AC 119 ms
41,820 KB
testcase_15 AC 121 ms
41,640 KB
testcase_16 AC 118 ms
42,068 KB
testcase_17 AC 114 ms
42,096 KB
testcase_18 AC 104 ms
41,712 KB
testcase_19 AC 116 ms
41,900 KB
testcase_20 AC 106 ms
41,448 KB
testcase_21 AC 114 ms
41,444 KB
testcase_22 AC 111 ms
41,396 KB
testcase_23 AC 104 ms
41,528 KB
testcase_24 AC 114 ms
41,832 KB
testcase_25 AC 105 ms
41,956 KB
testcase_26 AC 113 ms
41,952 KB
testcase_27 AC 105 ms
41,352 KB
testcase_28 AC 117 ms
41,904 KB
testcase_29 AC 115 ms
41,724 KB
testcase_30 AC 104 ms
41,604 KB
testcase_31 AC 114 ms
41,444 KB
testcase_32 AC 116 ms
41,664 KB
testcase_33 AC 116 ms
41,768 KB
testcase_34 AC 117 ms
42,076 KB
testcase_35 AC 132 ms
41,724 KB
testcase_36 AC 127 ms
42,192 KB
testcase_37 AC 135 ms
42,048 KB
testcase_38 AC 128 ms
41,972 KB
testcase_39 AC 125 ms
42,060 KB
testcase_40 AC 126 ms
41,560 KB
testcase_41 AC 128 ms
41,804 KB
testcase_42 AC 117 ms
41,852 KB
testcase_43 AC 127 ms
41,688 KB
testcase_44 AC 114 ms
41,748 KB
testcase_45 AC 126 ms
41,700 KB
testcase_46 AC 121 ms
42,196 KB
testcase_47 AC 124 ms
42,004 KB
testcase_48 AC 114 ms
42,040 KB
testcase_49 AC 128 ms
41,572 KB
testcase_50 AC 127 ms
41,928 KB
testcase_51 AC 125 ms
41,700 KB
testcase_52 AC 129 ms
42,064 KB
testcase_53 AC 131 ms
42,348 KB
testcase_54 AC 116 ms
42,044 KB
testcase_55 AC 116 ms
42,000 KB
testcase_56 AC 131 ms
41,584 KB
testcase_57 AC 120 ms
42,040 KB
testcase_58 AC 114 ms
41,816 KB
testcase_59 AC 115 ms
41,788 KB
testcase_60 AC 117 ms
41,452 KB
testcase_61 AC 117 ms
41,500 KB
testcase_62 AC 129 ms
41,872 KB
testcase_63 AC 125 ms
41,828 KB
testcase_64 AC 105 ms
41,588 KB
testcase_65 AC 129 ms
42,120 KB
testcase_66 AC 117 ms
41,484 KB
testcase_67 AC 126 ms
41,736 KB
testcase_68 AC 116 ms
41,844 KB
testcase_69 AC 123 ms
41,852 KB
testcase_70 AC 113 ms
42,288 KB
testcase_71 AC 118 ms
41,872 KB
testcase_72 AC 118 ms
41,848 KB
testcase_73 AC 126 ms
42,120 KB
testcase_74 AC 125 ms
42,196 KB
testcase_75 AC 115 ms
41,456 KB
testcase_76 AC 104 ms
41,828 KB
testcase_77 AC 126 ms
41,788 KB
testcase_78 AC 124 ms
42,004 KB
testcase_79 AC 124 ms
41,820 KB
testcase_80 AC 105 ms
41,788 KB
testcase_81 AC 129 ms
42,072 KB
testcase_82 AC 112 ms
41,872 KB
testcase_83 AC 113 ms
41,652 KB
testcase_84 AC 107 ms
41,888 KB
testcase_85 AC 105 ms
41,724 KB
testcase_86 AC 114 ms
41,888 KB
testcase_87 AC 118 ms
41,984 KB
testcase_88 AC 115 ms
41,832 KB
testcase_89 AC 117 ms
41,784 KB
testcase_90 AC 116 ms
41,824 KB
testcase_91 AC 110 ms
41,772 KB
testcase_92 AC 124 ms
41,844 KB
testcase_93 AC 111 ms
41,188 KB
testcase_94 AC 126 ms
41,512 KB
testcase_95 AC 121 ms
41,656 KB
testcase_96 AC 103 ms
42,012 KB
testcase_97 AC 108 ms
41,848 KB
testcase_98 AC 116 ms
41,796 KB
testcase_99 AC 120 ms
41,816 KB
testcase_100 AC 120 ms
41,492 KB
testcase_101 AC 119 ms
41,512 KB
testcase_102 AC 122 ms
41,600 KB
testcase_103 AC 121 ms
41,928 KB
testcase_104 AC 100 ms
41,504 KB
testcase_105 AC 104 ms
41,588 KB
testcase_106 AC 104 ms
41,728 KB
testcase_107 AC 117 ms
41,836 KB
testcase_108 AC 117 ms
41,856 KB
testcase_109 AC 114 ms
41,868 KB
testcase_110 AC 114 ms
41,560 KB
testcase_111 AC 118 ms
41,944 KB
testcase_112 AC 101 ms
41,724 KB
testcase_113 AC 116 ms
41,548 KB
testcase_114 AC 116 ms
41,812 KB
testcase_115 AC 121 ms
41,880 KB
testcase_116 AC 115 ms
41,804 KB
testcase_117 AC 114 ms
41,536 KB
testcase_118 AC 108 ms
41,944 KB
testcase_119 AC 111 ms
41,660 KB
testcase_120 AC 115 ms
41,404 KB
testcase_121 AC 110 ms
41,564 KB
testcase_122 AC 118 ms
41,832 KB
testcase_123 AC 133 ms
41,792 KB
testcase_124 AC 139 ms
41,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class No955 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		BigDecimal A = new BigDecimal(a);
		BigDecimal B = new BigDecimal(b);
		BigDecimal C = new BigDecimal(c);

		if(a == 0) {
			if(b == 0) {
				if(c == 0) {
					System.out.println(-1);
					return;
				} else {
					System.out.println(0);
					return;
				}
			} else {
				System.out.println(1);
				System.out.println(BigDecimal.ZERO.subtract(C).divide(B, 20, RoundingMode.HALF_EVEN));
				return;
			}
		}

		BigDecimal D = new BigDecimal(b);
		D = D.multiply(B).subtract(new BigDecimal(4).multiply(A).multiply(C));

		if(D.compareTo(BigDecimal.ZERO) == 1) {
			System.out.println(2);

			BigDecimal answer1 = BigDecimal.ZERO.subtract(B).subtract(sqrt(D)).divide(new BigDecimal(2).multiply(A), 20, RoundingMode.HALF_EVEN);
			BigDecimal answer2 = BigDecimal.ZERO.subtract(B).add(sqrt(D)).divide(new BigDecimal(2).multiply(A), 20, RoundingMode.HALF_EVEN);
			System.out.println(answer1.min(answer2));
			System.out.println(answer1.max(answer2));
		} else if(D.compareTo(BigDecimal.ZERO) == 0) {
			System.out.println(1);
			System.out.println(BigDecimal.ZERO.subtract(B).divide(new BigDecimal(2).multiply(A), 20, RoundingMode.HALF_EVEN));
		} else {
			System.out.println(0);
		}
	}

	public static BigDecimal sqrt(BigDecimal a) {
		BigDecimal a2 = a.add(BigDecimal.ZERO);

		for(int i = 0; i < 50; i++) {
			a2 = a2.subtract(a2.pow(2).subtract(a).divide(a2.multiply(new BigDecimal(2)), 30, RoundingMode.HALF_EVEN));
		}
		return a2;
	}

}
0