結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー | 37zigen |
提出日時 | 2019-12-18 01:40:39 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,309 bytes |
コンパイル時間 | 2,021 ms |
コンパイル使用メモリ | 82,700 KB |
実行使用メモリ | 54,576 KB |
最終ジャッジ日時 | 2024-07-07 00:12:13 |
合計ジャッジ時間 | 17,816 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 109 ms
54,472 KB |
testcase_01 | AC | 98 ms
52,924 KB |
testcase_02 | AC | 108 ms
53,908 KB |
testcase_03 | AC | 108 ms
54,176 KB |
testcase_04 | AC | 113 ms
54,368 KB |
testcase_05 | AC | 103 ms
53,188 KB |
testcase_06 | AC | 97 ms
52,816 KB |
testcase_07 | AC | 91 ms
52,780 KB |
testcase_08 | AC | 98 ms
54,456 KB |
testcase_09 | AC | 98 ms
53,260 KB |
testcase_10 | AC | 97 ms
53,188 KB |
testcase_11 | AC | 101 ms
53,060 KB |
testcase_12 | AC | 105 ms
54,100 KB |
testcase_13 | AC | 108 ms
54,272 KB |
testcase_14 | AC | 105 ms
54,040 KB |
testcase_15 | AC | 99 ms
53,316 KB |
testcase_16 | AC | 105 ms
54,232 KB |
testcase_17 | AC | 101 ms
53,444 KB |
testcase_18 | AC | 98 ms
52,976 KB |
testcase_19 | AC | 100 ms
53,200 KB |
testcase_20 | AC | 98 ms
53,136 KB |
testcase_21 | AC | 108 ms
54,152 KB |
testcase_22 | AC | 110 ms
54,424 KB |
testcase_23 | AC | 110 ms
54,152 KB |
testcase_24 | AC | 100 ms
53,196 KB |
testcase_25 | AC | 102 ms
53,160 KB |
testcase_26 | AC | 101 ms
53,012 KB |
testcase_27 | AC | 103 ms
53,032 KB |
testcase_28 | AC | 107 ms
53,320 KB |
testcase_29 | AC | 112 ms
54,048 KB |
testcase_30 | AC | 111 ms
54,060 KB |
testcase_31 | AC | 102 ms
53,180 KB |
testcase_32 | AC | 98 ms
52,948 KB |
testcase_33 | AC | 111 ms
54,204 KB |
testcase_34 | AC | 104 ms
53,296 KB |
testcase_35 | AC | 106 ms
53,420 KB |
testcase_36 | AC | 113 ms
54,320 KB |
testcase_37 | AC | 118 ms
54,260 KB |
testcase_38 | AC | 107 ms
53,256 KB |
testcase_39 | AC | 109 ms
53,608 KB |
testcase_40 | AC | 111 ms
54,284 KB |
testcase_41 | AC | 100 ms
53,068 KB |
testcase_42 | AC | 109 ms
53,808 KB |
testcase_43 | AC | 110 ms
54,152 KB |
testcase_44 | AC | 100 ms
53,364 KB |
testcase_45 | AC | 105 ms
53,292 KB |
testcase_46 | AC | 109 ms
54,088 KB |
testcase_47 | AC | 112 ms
54,456 KB |
testcase_48 | AC | 101 ms
53,580 KB |
testcase_49 | AC | 114 ms
54,356 KB |
testcase_50 | AC | 113 ms
54,380 KB |
testcase_51 | AC | 101 ms
53,236 KB |
testcase_52 | AC | 100 ms
53,372 KB |
testcase_53 | AC | 107 ms
54,436 KB |
testcase_54 | AC | 118 ms
54,452 KB |
testcase_55 | AC | 108 ms
54,036 KB |
testcase_56 | AC | 110 ms
54,488 KB |
testcase_57 | AC | 99 ms
53,272 KB |
testcase_58 | AC | 109 ms
54,576 KB |
testcase_59 | AC | 95 ms
52,912 KB |
testcase_60 | AC | 98 ms
53,004 KB |
testcase_61 | AC | 106 ms
54,104 KB |
testcase_62 | AC | 104 ms
53,320 KB |
testcase_63 | AC | 101 ms
53,304 KB |
testcase_64 | AC | 111 ms
54,156 KB |
testcase_65 | AC | 97 ms
52,732 KB |
testcase_66 | AC | 93 ms
52,812 KB |
testcase_67 | AC | 96 ms
52,540 KB |
testcase_68 | AC | 105 ms
53,160 KB |
testcase_69 | AC | 111 ms
54,324 KB |
testcase_70 | AC | 110 ms
54,184 KB |
testcase_71 | AC | 95 ms
52,488 KB |
testcase_72 | AC | 95 ms
52,416 KB |
testcase_73 | AC | 105 ms
53,308 KB |
testcase_74 | AC | 105 ms
53,752 KB |
testcase_75 | AC | 106 ms
54,216 KB |
testcase_76 | AC | 111 ms
53,912 KB |
testcase_77 | AC | 103 ms
53,224 KB |
testcase_78 | AC | 103 ms
53,432 KB |
testcase_79 | AC | 107 ms
53,304 KB |
testcase_80 | AC | 103 ms
53,420 KB |
testcase_81 | AC | 111 ms
54,280 KB |
testcase_82 | AC | 110 ms
54,208 KB |
testcase_83 | AC | 109 ms
54,056 KB |
testcase_84 | AC | 93 ms
52,936 KB |
testcase_85 | AC | 113 ms
54,212 KB |
testcase_86 | AC | 102 ms
53,084 KB |
testcase_87 | AC | 104 ms
52,884 KB |
testcase_88 | AC | 110 ms
54,176 KB |
testcase_89 | AC | 99 ms
53,004 KB |
testcase_90 | AC | 96 ms
52,624 KB |
testcase_91 | AC | 109 ms
54,316 KB |
testcase_92 | AC | 101 ms
53,172 KB |
testcase_93 | AC | 101 ms
53,180 KB |
testcase_94 | AC | 110 ms
54,172 KB |
testcase_95 | WA | - |
testcase_96 | WA | - |
testcase_97 | AC | 110 ms
54,304 KB |
testcase_98 | AC | 102 ms
53,224 KB |
testcase_99 | WA | - |
testcase_100 | AC | 111 ms
54,256 KB |
testcase_101 | AC | 109 ms
54,124 KB |
testcase_102 | AC | 107 ms
54,220 KB |
testcase_103 | AC | 97 ms
52,892 KB |
testcase_104 | AC | 109 ms
53,960 KB |
testcase_105 | AC | 108 ms
54,052 KB |
testcase_106 | AC | 95 ms
53,120 KB |
testcase_107 | AC | 97 ms
53,292 KB |
testcase_108 | AC | 114 ms
54,048 KB |
testcase_109 | AC | 98 ms
52,880 KB |
testcase_110 | AC | 107 ms
54,056 KB |
testcase_111 | AC | 97 ms
53,076 KB |
testcase_112 | AC | 103 ms
53,168 KB |
testcase_113 | AC | 98 ms
53,084 KB |
testcase_114 | AC | 95 ms
54,548 KB |
testcase_115 | AC | 105 ms
54,272 KB |
testcase_116 | AC | 111 ms
54,148 KB |
testcase_117 | AC | 98 ms
53,016 KB |
testcase_118 | AC | 103 ms
53,140 KB |
testcase_119 | AC | 94 ms
52,996 KB |
testcase_120 | AC | 97 ms
53,368 KB |
testcase_121 | AC | 103 ms
52,980 KB |
testcase_122 | AC | 117 ms
54,448 KB |
testcase_123 | AC | 119 ms
54,172 KB |
testcase_124 | AC | 104 ms
53,288 KB |
ソースコード
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) { Scanner sc = new Scanner(System.in); long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong(); // for (long a = -10; a <= 10; ++a) // for (long b = -10; b <= 10; ++b) // for (long c = -10; c <= 10; ++c) new Main().run(a, b, c); } void run(long a, long b, long c) { 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+c=0 // b!=0 System.out.println(1); System.out.println(-(double) c / b); } else if (a != 0) { BigDecimal DD = BigDecimal.valueOf(b * b) .subtract(BigDecimal.valueOf(4).multiply(BigDecimal.valueOf(a * c))); if (DD.compareTo(BigDecimal.ZERO) == -1) { System.out.println(0); } else if (DD.compareTo(BigDecimal.ZERO) == 0) { System.out.println(1); System.out.println(BigDecimal.valueOf(-b).divide(BigDecimal.valueOf(2 * a), BigDecimal.ROUND_HALF_UP) .doubleValue()); } else { System.out.println(2); double x1 = BigDecimal.valueOf(-b).subtract(sqrt(DD, 50)) .divide(BigDecimal.valueOf(2 * a), BigDecimal.ROUND_HALF_UP).doubleValue(); double x2 = BigDecimal.valueOf(-b).add(sqrt(DD, 50)) .divide(BigDecimal.valueOf(2 * a), BigDecimal.ROUND_HALF_UP).doubleValue();// (double)(-b+Math.sqrt(DD))/(2*a)); if (x1 > x2) { double tmp = x1; x1 = x2; x2 = tmp; } System.out.println(x1); System.out.println(x2); } } } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } 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; } }