結果

問題 No.955 ax^2+bx+c=0
ユーザー agataYMGTagataYMGT
提出日時 2019-12-28 11:05:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,552 bytes
コンパイル時間 3,842 ms
コンパイル使用メモリ 78,332 KB
実行使用メモリ 41,892 KB
最終ジャッジ日時 2024-04-19 14:49:09
合計ジャッジ時間 21,338 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
41,864 KB
testcase_01 AC 118 ms
41,384 KB
testcase_02 AC 120 ms
41,404 KB
testcase_03 AC 114 ms
40,960 KB
testcase_04 AC 119 ms
41,392 KB
testcase_05 AC 105 ms
41,480 KB
testcase_06 AC 103 ms
41,068 KB
testcase_07 AC 115 ms
39,980 KB
testcase_08 AC 116 ms
40,948 KB
testcase_09 AC 116 ms
41,324 KB
testcase_10 AC 114 ms
41,088 KB
testcase_11 AC 117 ms
41,228 KB
testcase_12 AC 118 ms
41,400 KB
testcase_13 AC 118 ms
41,576 KB
testcase_14 AC 116 ms
41,284 KB
testcase_15 AC 113 ms
40,416 KB
testcase_16 AC 109 ms
41,276 KB
testcase_17 AC 105 ms
41,088 KB
testcase_18 AC 117 ms
40,876 KB
testcase_19 AC 103 ms
40,948 KB
testcase_20 AC 111 ms
40,952 KB
testcase_21 AC 117 ms
40,856 KB
testcase_22 AC 105 ms
40,932 KB
testcase_23 AC 116 ms
41,272 KB
testcase_24 AC 104 ms
41,044 KB
testcase_25 AC 115 ms
41,612 KB
testcase_26 AC 114 ms
41,184 KB
testcase_27 AC 106 ms
41,268 KB
testcase_28 AC 114 ms
41,548 KB
testcase_29 AC 120 ms
41,340 KB
testcase_30 AC 101 ms
41,324 KB
testcase_31 AC 103 ms
41,096 KB
testcase_32 AC 123 ms
41,608 KB
testcase_33 AC 124 ms
41,076 KB
testcase_34 AC 135 ms
41,404 KB
testcase_35 AC 123 ms
41,564 KB
testcase_36 AC 124 ms
41,688 KB
testcase_37 AC 133 ms
40,180 KB
testcase_38 AC 142 ms
41,876 KB
testcase_39 AC 129 ms
40,592 KB
testcase_40 AC 128 ms
41,564 KB
testcase_41 AC 130 ms
41,764 KB
testcase_42 AC 123 ms
41,748 KB
testcase_43 AC 132 ms
41,604 KB
testcase_44 AC 132 ms
41,604 KB
testcase_45 AC 122 ms
41,464 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 129 ms
40,532 KB
testcase_59 WA -
testcase_60 AC 109 ms
40,192 KB
testcase_61 AC 103 ms
41,220 KB
testcase_62 AC 132 ms
40,296 KB
testcase_63 WA -
testcase_64 AC 105 ms
39,896 KB
testcase_65 WA -
testcase_66 AC 117 ms
41,432 KB
testcase_67 AC 139 ms
41,816 KB
testcase_68 AC 121 ms
41,248 KB
testcase_69 AC 131 ms
41,728 KB
testcase_70 WA -
testcase_71 AC 124 ms
41,488 KB
testcase_72 AC 115 ms
41,312 KB
testcase_73 AC 131 ms
41,664 KB
testcase_74 AC 134 ms
41,892 KB
testcase_75 AC 112 ms
41,384 KB
testcase_76 AC 106 ms
41,156 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 AC 122 ms
41,348 KB
testcase_81 AC 139 ms
41,740 KB
testcase_82 AC 117 ms
41,520 KB
testcase_83 AC 106 ms
41,556 KB
testcase_84 AC 115 ms
41,032 KB
testcase_85 AC 108 ms
41,360 KB
testcase_86 AC 119 ms
41,196 KB
testcase_87 AC 114 ms
41,004 KB
testcase_88 AC 118 ms
41,200 KB
testcase_89 AC 108 ms
41,460 KB
testcase_90 AC 115 ms
41,000 KB
testcase_91 AC 115 ms
41,308 KB
testcase_92 AC 131 ms
41,200 KB
testcase_93 AC 106 ms
41,068 KB
testcase_94 AC 111 ms
40,964 KB
testcase_95 AC 116 ms
41,508 KB
testcase_96 AC 115 ms
41,340 KB
testcase_97 AC 105 ms
41,360 KB
testcase_98 AC 109 ms
41,200 KB
testcase_99 AC 119 ms
41,276 KB
testcase_100 AC 125 ms
41,484 KB
testcase_101 AC 115 ms
41,152 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 123 ms
41,252 KB
testcase_123 AC 134 ms
41,440 KB
testcase_124 WA -
権限があれば一括ダウンロードができます

ソースコード

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();

		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(-c);
				return;
			}
		}

		BigDecimal A = new BigDecimal(a);
		BigDecimal B = new BigDecimal(b);
		BigDecimal C = new BigDecimal(c);

		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);
			System.out.println(BigDecimal.ZERO.subtract(B).subtract(sqrt(D)).divide(new BigDecimal(2).multiply(A), 20, RoundingMode.HALF_EVEN));
			System.out.println(BigDecimal.ZERO.subtract(B).add(sqrt(D)).divide(new BigDecimal(2).multiply(A), 20, RoundingMode.HALF_EVEN));
		} 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 < 100; i++) {
			a2 = a2.subtract(a2.pow(2).subtract(a).divide(a2.multiply(new BigDecimal(2)), 20, RoundingMode.HALF_EVEN));
		}
		return a2;
	}

}
0