結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー | k_6101 |
提出日時 | 2019-12-21 16:12:31 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,212 bytes |
コンパイル時間 | 3,351 ms |
コンパイル使用メモリ | 103,224 KB |
実行使用メモリ | 42,188 KB |
最終ジャッジ日時 | 2024-07-19 15:56:16 |
合計ジャッジ時間 | 22,474 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
41,420 KB |
testcase_01 | WA | - |
testcase_02 | AC | 113 ms
40,108 KB |
testcase_03 | AC | 108 ms
39,864 KB |
testcase_04 | AC | 124 ms
41,312 KB |
testcase_05 | AC | 125 ms
41,140 KB |
testcase_06 | AC | 126 ms
41,368 KB |
testcase_07 | AC | 124 ms
41,188 KB |
testcase_08 | AC | 126 ms
41,396 KB |
testcase_09 | AC | 125 ms
41,228 KB |
testcase_10 | AC | 126 ms
41,124 KB |
testcase_11 | AC | 126 ms
41,300 KB |
testcase_12 | AC | 126 ms
41,260 KB |
testcase_13 | AC | 123 ms
41,140 KB |
testcase_14 | AC | 128 ms
41,284 KB |
testcase_15 | AC | 127 ms
41,652 KB |
testcase_16 | AC | 127 ms
41,148 KB |
testcase_17 | AC | 114 ms
40,168 KB |
testcase_18 | AC | 125 ms
41,356 KB |
testcase_19 | AC | 113 ms
40,040 KB |
testcase_20 | AC | 129 ms
40,968 KB |
testcase_21 | AC | 117 ms
41,372 KB |
testcase_22 | AC | 113 ms
40,120 KB |
testcase_23 | AC | 124 ms
41,040 KB |
testcase_24 | AC | 122 ms
41,332 KB |
testcase_25 | AC | 124 ms
41,128 KB |
testcase_26 | AC | 125 ms
41,124 KB |
testcase_27 | AC | 123 ms
41,040 KB |
testcase_28 | AC | 116 ms
41,132 KB |
testcase_29 | AC | 125 ms
41,164 KB |
testcase_30 | AC | 122 ms
41,012 KB |
testcase_31 | AC | 122 ms
41,020 KB |
testcase_32 | AC | 124 ms
41,024 KB |
testcase_33 | AC | 110 ms
41,124 KB |
testcase_34 | AC | 120 ms
41,652 KB |
testcase_35 | AC | 130 ms
41,500 KB |
testcase_36 | AC | 120 ms
41,984 KB |
testcase_37 | AC | 132 ms
41,528 KB |
testcase_38 | AC | 128 ms
41,492 KB |
testcase_39 | AC | 131 ms
41,556 KB |
testcase_40 | AC | 129 ms
41,576 KB |
testcase_41 | AC | 130 ms
41,712 KB |
testcase_42 | AC | 132 ms
41,652 KB |
testcase_43 | AC | 133 ms
41,544 KB |
testcase_44 | AC | 134 ms
41,576 KB |
testcase_45 | AC | 130 ms
41,460 KB |
testcase_46 | AC | 133 ms
41,680 KB |
testcase_47 | AC | 130 ms
41,640 KB |
testcase_48 | AC | 134 ms
41,648 KB |
testcase_49 | AC | 131 ms
41,528 KB |
testcase_50 | AC | 131 ms
41,524 KB |
testcase_51 | AC | 119 ms
40,292 KB |
testcase_52 | AC | 131 ms
41,800 KB |
testcase_53 | AC | 130 ms
41,780 KB |
testcase_54 | AC | 136 ms
41,716 KB |
testcase_55 | AC | 129 ms
41,496 KB |
testcase_56 | AC | 130 ms
41,448 KB |
testcase_57 | AC | 130 ms
41,508 KB |
testcase_58 | AC | 136 ms
42,188 KB |
testcase_59 | AC | 137 ms
41,872 KB |
testcase_60 | AC | 121 ms
41,012 KB |
testcase_61 | AC | 123 ms
41,580 KB |
testcase_62 | AC | 130 ms
41,576 KB |
testcase_63 | AC | 120 ms
40,468 KB |
testcase_64 | AC | 123 ms
41,172 KB |
testcase_65 | AC | 133 ms
41,556 KB |
testcase_66 | AC | 126 ms
41,232 KB |
testcase_67 | AC | 134 ms
41,556 KB |
testcase_68 | AC | 125 ms
41,200 KB |
testcase_69 | AC | 137 ms
41,756 KB |
testcase_70 | AC | 131 ms
41,768 KB |
testcase_71 | AC | 123 ms
41,104 KB |
testcase_72 | AC | 121 ms
41,084 KB |
testcase_73 | AC | 132 ms
41,676 KB |
testcase_74 | AC | 119 ms
41,940 KB |
testcase_75 | AC | 112 ms
39,884 KB |
testcase_76 | AC | 123 ms
41,384 KB |
testcase_77 | AC | 133 ms
41,620 KB |
testcase_78 | AC | 128 ms
40,492 KB |
testcase_79 | AC | 133 ms
41,752 KB |
testcase_80 | AC | 125 ms
41,428 KB |
testcase_81 | AC | 118 ms
41,364 KB |
testcase_82 | AC | 125 ms
41,608 KB |
testcase_83 | WA | - |
testcase_84 | WA | - |
testcase_85 | WA | - |
testcase_86 | WA | - |
testcase_87 | AC | 126 ms
41,264 KB |
testcase_88 | AC | 127 ms
41,396 KB |
testcase_89 | AC | 125 ms
41,060 KB |
testcase_90 | WA | - |
testcase_91 | WA | - |
testcase_92 | AC | 127 ms
41,060 KB |
testcase_93 | AC | 128 ms
41,304 KB |
testcase_94 | WA | - |
testcase_95 | WA | - |
testcase_96 | WA | - |
testcase_97 | WA | - |
testcase_98 | WA | - |
testcase_99 | WA | - |
testcase_100 | AC | 125 ms
41,000 KB |
testcase_101 | WA | - |
testcase_102 | AC | 129 ms
41,428 KB |
testcase_103 | AC | 125 ms
41,112 KB |
testcase_104 | AC | 127 ms
41,384 KB |
testcase_105 | AC | 128 ms
41,012 KB |
testcase_106 | AC | 128 ms
41,280 KB |
testcase_107 | AC | 128 ms
41,316 KB |
testcase_108 | AC | 127 ms
41,484 KB |
testcase_109 | AC | 131 ms
41,324 KB |
testcase_110 | AC | 127 ms
41,288 KB |
testcase_111 | AC | 131 ms
40,992 KB |
testcase_112 | AC | 125 ms
41,020 KB |
testcase_113 | AC | 114 ms
40,308 KB |
testcase_114 | AC | 115 ms
40,332 KB |
testcase_115 | AC | 126 ms
41,768 KB |
testcase_116 | AC | 129 ms
41,040 KB |
testcase_117 | AC | 129 ms
41,412 KB |
testcase_118 | AC | 108 ms
39,784 KB |
testcase_119 | AC | 128 ms
41,116 KB |
testcase_120 | AC | 126 ms
41,092 KB |
testcase_121 | AC | 125 ms
41,088 KB |
testcase_122 | AC | 133 ms
41,644 KB |
testcase_123 | AC | 124 ms
41,388 KB |
testcase_124 | WA | - |
ソースコード
import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.MathContext; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== public void solve() { long A = Long.parseLong(sc.next()); long B = Long.parseLong(sc.next()); long C = Long.parseLong(sc.next()); if(A == 0 && B == 0) { if(C == 0) out.println(-1); else out.println(0); } else if(A == 0) { out.println(1); out.println(String.format("%.14f", (double)C * -1 /B)); } else if(B == 0) { if(C == 0) { out.println(1); out.println(0); } else if((long)A * C < 0) { out.println(0); } else { double X = Math.sqrt((double)C*-1/A); out.println(2); out.println("-" + String.format("%.14f", X)); out.println(String.format("%.14f", X)); } } else if(C == 0) { out.println(2); if(B > 0) { out.println(String.format("%.14f", (double)B * -1 / A)); out.println(0); } else { out.println(0); out.println(String.format("%.14f", (double)B * -1 / A)); } } else if((B*B - 4*A*C) < 0) { out.println(0); } else { BigDecimal wk = sqrt(B*B - 4*A*C); if(wk.equals(BigDecimal.ZERO)) { out.println(1); out.println(String.format("%.14f", ((double)B * -1) / A / 2)); } else { out.println(2); if(A > 0) { out.println(String.format("%.14f", (new BigDecimal(B).negate().subtract(wk).divide(new BigDecimal(A*2),14,BigDecimal.ROUND_UP)))); out.println(String.format("%.14f", (new BigDecimal(B).negate().add(wk).divide(new BigDecimal(A*2),14,BigDecimal.ROUND_UP)))); } else { out.println(String.format("%.14f", (new BigDecimal(B).negate().add(wk).divide(new BigDecimal(A*2),14,BigDecimal.ROUND_UP)))); out.println(String.format("%.14f", (new BigDecimal(B).negate().subtract(wk).divide(new BigDecimal(A*2),14,BigDecimal.ROUND_UP)))); } } } } BigDecimal sqrt(long a) { MathContext cx = new MathContext(20); BigDecimal cur = BigDecimal.ONE; // (x+a/x)/2 for(int rep = 0;rep < 50;rep++){ cur = cur.add(BigDecimal.valueOf(a).divide(cur, cx)).divide(BigDecimal.valueOf(2), cx); } return cur; } }