結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー | k_6101 |
提出日時 | 2020-01-02 01:07:40 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 3,258 bytes |
コンパイル時間 | 3,739 ms |
コンパイル使用メモリ | 96,260 KB |
実行使用メモリ | 55,876 KB |
最終ジャッジ日時 | 2024-11-22 17:36:00 |
合計ジャッジ時間 | 23,319 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 134 ms
54,452 KB |
testcase_01 | AC | 146 ms
54,172 KB |
testcase_02 | AC | 120 ms
54,016 KB |
testcase_03 | AC | 123 ms
53,540 KB |
testcase_04 | AC | 124 ms
53,756 KB |
testcase_05 | AC | 127 ms
53,928 KB |
testcase_06 | AC | 128 ms
53,872 KB |
testcase_07 | AC | 126 ms
54,184 KB |
testcase_08 | AC | 128 ms
53,912 KB |
testcase_09 | AC | 125 ms
53,984 KB |
testcase_10 | AC | 127 ms
54,216 KB |
testcase_11 | AC | 128 ms
53,664 KB |
testcase_12 | AC | 127 ms
53,792 KB |
testcase_13 | AC | 125 ms
53,968 KB |
testcase_14 | AC | 126 ms
54,040 KB |
testcase_15 | AC | 130 ms
54,040 KB |
testcase_16 | AC | 131 ms
53,832 KB |
testcase_17 | AC | 129 ms
54,100 KB |
testcase_18 | AC | 128 ms
54,036 KB |
testcase_19 | AC | 127 ms
53,800 KB |
testcase_20 | AC | 129 ms
53,976 KB |
testcase_21 | AC | 127 ms
53,956 KB |
testcase_22 | AC | 129 ms
53,996 KB |
testcase_23 | AC | 126 ms
53,692 KB |
testcase_24 | AC | 127 ms
54,180 KB |
testcase_25 | AC | 125 ms
54,232 KB |
testcase_26 | AC | 125 ms
54,112 KB |
testcase_27 | AC | 131 ms
53,720 KB |
testcase_28 | AC | 113 ms
52,620 KB |
testcase_29 | AC | 112 ms
52,688 KB |
testcase_30 | AC | 128 ms
53,924 KB |
testcase_31 | AC | 127 ms
53,980 KB |
testcase_32 | AC | 127 ms
53,896 KB |
testcase_33 | AC | 129 ms
54,172 KB |
testcase_34 | AC | 136 ms
54,144 KB |
testcase_35 | AC | 136 ms
54,188 KB |
testcase_36 | AC | 137 ms
54,128 KB |
testcase_37 | AC | 134 ms
54,020 KB |
testcase_38 | AC | 134 ms
54,204 KB |
testcase_39 | AC | 138 ms
54,364 KB |
testcase_40 | AC | 136 ms
54,344 KB |
testcase_41 | AC | 139 ms
54,520 KB |
testcase_42 | AC | 136 ms
54,372 KB |
testcase_43 | AC | 136 ms
53,908 KB |
testcase_44 | AC | 137 ms
54,540 KB |
testcase_45 | AC | 136 ms
54,176 KB |
testcase_46 | AC | 138 ms
54,352 KB |
testcase_47 | AC | 135 ms
54,116 KB |
testcase_48 | AC | 133 ms
54,384 KB |
testcase_49 | AC | 132 ms
53,960 KB |
testcase_50 | AC | 130 ms
54,172 KB |
testcase_51 | AC | 131 ms
54,760 KB |
testcase_52 | AC | 129 ms
54,092 KB |
testcase_53 | AC | 133 ms
54,280 KB |
testcase_54 | AC | 135 ms
54,356 KB |
testcase_55 | AC | 133 ms
54,360 KB |
testcase_56 | AC | 134 ms
54,440 KB |
testcase_57 | AC | 131 ms
54,424 KB |
testcase_58 | AC | 136 ms
53,884 KB |
testcase_59 | AC | 143 ms
54,220 KB |
testcase_60 | AC | 121 ms
53,784 KB |
testcase_61 | AC | 126 ms
53,796 KB |
testcase_62 | AC | 133 ms
54,400 KB |
testcase_63 | AC | 139 ms
54,292 KB |
testcase_64 | AC | 129 ms
53,784 KB |
testcase_65 | AC | 135 ms
54,456 KB |
testcase_66 | AC | 125 ms
53,728 KB |
testcase_67 | AC | 134 ms
53,956 KB |
testcase_68 | AC | 126 ms
55,876 KB |
testcase_69 | AC | 133 ms
54,428 KB |
testcase_70 | AC | 134 ms
54,524 KB |
testcase_71 | AC | 123 ms
53,872 KB |
testcase_72 | AC | 127 ms
53,880 KB |
testcase_73 | AC | 137 ms
54,060 KB |
testcase_74 | AC | 135 ms
53,972 KB |
testcase_75 | AC | 129 ms
54,124 KB |
testcase_76 | AC | 126 ms
53,788 KB |
testcase_77 | AC | 135 ms
54,288 KB |
testcase_78 | AC | 116 ms
52,808 KB |
testcase_79 | AC | 133 ms
54,104 KB |
testcase_80 | AC | 126 ms
53,968 KB |
testcase_81 | AC | 134 ms
54,340 KB |
testcase_82 | AC | 127 ms
54,048 KB |
testcase_83 | AC | 128 ms
53,672 KB |
testcase_84 | AC | 130 ms
53,992 KB |
testcase_85 | AC | 129 ms
54,020 KB |
testcase_86 | AC | 128 ms
53,876 KB |
testcase_87 | AC | 127 ms
53,928 KB |
testcase_88 | AC | 124 ms
53,704 KB |
testcase_89 | AC | 123 ms
53,680 KB |
testcase_90 | AC | 131 ms
54,092 KB |
testcase_91 | AC | 126 ms
53,528 KB |
testcase_92 | AC | 127 ms
54,020 KB |
testcase_93 | AC | 126 ms
53,920 KB |
testcase_94 | AC | 125 ms
54,388 KB |
testcase_95 | AC | 127 ms
53,676 KB |
testcase_96 | AC | 130 ms
54,172 KB |
testcase_97 | AC | 128 ms
54,024 KB |
testcase_98 | AC | 132 ms
54,212 KB |
testcase_99 | AC | 125 ms
54,172 KB |
testcase_100 | AC | 126 ms
53,956 KB |
testcase_101 | AC | 125 ms
54,052 KB |
testcase_102 | AC | 123 ms
54,080 KB |
testcase_103 | AC | 125 ms
53,964 KB |
testcase_104 | AC | 114 ms
52,712 KB |
testcase_105 | AC | 124 ms
53,892 KB |
testcase_106 | AC | 130 ms
54,184 KB |
testcase_107 | AC | 126 ms
53,976 KB |
testcase_108 | AC | 127 ms
54,032 KB |
testcase_109 | AC | 127 ms
53,720 KB |
testcase_110 | AC | 130 ms
54,084 KB |
testcase_111 | AC | 129 ms
54,028 KB |
testcase_112 | AC | 128 ms
54,080 KB |
testcase_113 | AC | 128 ms
53,812 KB |
testcase_114 | AC | 131 ms
53,924 KB |
testcase_115 | AC | 127 ms
53,776 KB |
testcase_116 | AC | 124 ms
53,804 KB |
testcase_117 | AC | 127 ms
54,032 KB |
testcase_118 | AC | 127 ms
53,920 KB |
testcase_119 | AC | 124 ms
53,820 KB |
testcase_120 | AC | 126 ms
53,880 KB |
testcase_121 | AC | 130 ms
53,820 KB |
testcase_122 | AC | 135 ms
54,376 KB |
testcase_123 | AC | 128 ms
53,960 KB |
testcase_124 | AC | 129 ms
54,088 KB |
ソースコード
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) { if((B > 0 && A > 0) || (B < 0 && A < 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 { if((B*B - 4*A*C) == 0) { out.println(1); out.println(String.format("%.14f", ((double)B * -1) / A / 2)); } else { BigDecimal wk = sqrt(B*B - 4*A*C); 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; } }