結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー | 37zigen |
提出日時 | 2019-12-18 01:10:35 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,268 bytes |
コンパイル時間 | 2,496 ms |
コンパイル使用メモリ | 79,676 KB |
実行使用メモリ | 42,144 KB |
最終ジャッジ日時 | 2024-07-07 00:08:31 |
合計ジャッジ時間 | 18,360 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 114 ms
41,672 KB |
testcase_02 | AC | 114 ms
41,532 KB |
testcase_03 | AC | 115 ms
41,376 KB |
testcase_04 | AC | 125 ms
41,472 KB |
testcase_05 | AC | 124 ms
41,316 KB |
testcase_06 | AC | 120 ms
41,432 KB |
testcase_07 | AC | 117 ms
41,272 KB |
testcase_08 | AC | 119 ms
41,712 KB |
testcase_09 | AC | 112 ms
41,408 KB |
testcase_10 | AC | 105 ms
41,920 KB |
testcase_11 | AC | 113 ms
41,224 KB |
testcase_12 | AC | 113 ms
41,512 KB |
testcase_13 | AC | 110 ms
41,504 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 102 ms
41,656 KB |
testcase_25 | AC | 112 ms
41,444 KB |
testcase_26 | AC | 95 ms
41,512 KB |
testcase_27 | AC | 117 ms
41,592 KB |
testcase_28 | AC | 115 ms
41,396 KB |
testcase_29 | AC | 108 ms
41,552 KB |
testcase_30 | AC | 122 ms
41,044 KB |
testcase_31 | AC | 110 ms
41,512 KB |
testcase_32 | AC | 119 ms
41,300 KB |
testcase_33 | AC | 111 ms
41,432 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
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 | WA | - |
testcase_59 | WA | - |
testcase_60 | AC | 115 ms
41,332 KB |
testcase_61 | AC | 114 ms
41,520 KB |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | AC | 112 ms
41,180 KB |
testcase_65 | WA | - |
testcase_66 | AC | 113 ms
41,644 KB |
testcase_67 | WA | - |
testcase_68 | AC | 112 ms
41,552 KB |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | AC | 115 ms
41,392 KB |
testcase_72 | AC | 100 ms
41,212 KB |
testcase_73 | WA | - |
testcase_74 | WA | - |
testcase_75 | AC | 111 ms
41,168 KB |
testcase_76 | AC | 113 ms
41,228 KB |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | WA | - |
testcase_80 | AC | 112 ms
41,296 KB |
testcase_81 | WA | - |
testcase_82 | AC | 105 ms
41,280 KB |
testcase_83 | AC | 106 ms
41,820 KB |
testcase_84 | AC | 115 ms
41,584 KB |
testcase_85 | AC | 105 ms
41,140 KB |
testcase_86 | AC | 103 ms
41,800 KB |
testcase_87 | AC | 119 ms
41,776 KB |
testcase_88 | AC | 114 ms
41,456 KB |
testcase_89 | AC | 110 ms
41,692 KB |
testcase_90 | AC | 102 ms
41,444 KB |
testcase_91 | AC | 103 ms
41,796 KB |
testcase_92 | AC | 98 ms
41,540 KB |
testcase_93 | AC | 114 ms
41,428 KB |
testcase_94 | AC | 111 ms
41,724 KB |
testcase_95 | AC | 117 ms
41,472 KB |
testcase_96 | AC | 113 ms
41,400 KB |
testcase_97 | AC | 117 ms
41,148 KB |
testcase_98 | AC | 121 ms
41,668 KB |
testcase_99 | AC | 105 ms
41,620 KB |
testcase_100 | AC | 101 ms
41,236 KB |
testcase_101 | AC | 116 ms
41,032 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 | WA | - |
testcase_123 | WA | - |
testcase_124 | WA | - |
ソースコード
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+0=0 System.out.println(1); System.out.println((double) c / a); } 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((double) (-b) / (2 * a)); } 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) throw new AssertionError(); } } // BigDecimal s2_50 = sqrt(new BigDecimal(2), 50); // System.out.println(s2_50); // System.out.println(s2_50.multiply(s2_50)); } 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; } }