結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー | nmnmnmnmnmnmnm |
提出日時 | 2019-12-10 20:31:26 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 1,987 bytes |
コンパイル時間 | 2,464 ms |
コンパイル使用メモリ | 79,800 KB |
実行使用メモリ | 42,096 KB |
最終ジャッジ日時 | 2024-09-18 22:07:46 |
合計ジャッジ時間 | 23,468 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 140 ms
41,360 KB |
testcase_01 | AC | 144 ms
41,520 KB |
testcase_02 | AC | 146 ms
41,276 KB |
testcase_03 | AC | 137 ms
41,584 KB |
testcase_04 | AC | 141 ms
41,280 KB |
testcase_05 | AC | 140 ms
40,968 KB |
testcase_06 | AC | 139 ms
41,328 KB |
testcase_07 | AC | 138 ms
41,008 KB |
testcase_08 | AC | 148 ms
41,432 KB |
testcase_09 | AC | 138 ms
41,176 KB |
testcase_10 | AC | 144 ms
41,688 KB |
testcase_11 | AC | 143 ms
41,180 KB |
testcase_12 | AC | 144 ms
41,264 KB |
testcase_13 | AC | 142 ms
41,004 KB |
testcase_14 | AC | 146 ms
41,636 KB |
testcase_15 | AC | 148 ms
41,392 KB |
testcase_16 | AC | 143 ms
41,344 KB |
testcase_17 | AC | 149 ms
41,532 KB |
testcase_18 | AC | 144 ms
41,216 KB |
testcase_19 | AC | 140 ms
41,116 KB |
testcase_20 | AC | 141 ms
41,444 KB |
testcase_21 | AC | 145 ms
41,216 KB |
testcase_22 | AC | 143 ms
41,204 KB |
testcase_23 | AC | 142 ms
41,560 KB |
testcase_24 | AC | 145 ms
41,464 KB |
testcase_25 | AC | 144 ms
41,340 KB |
testcase_26 | AC | 148 ms
41,172 KB |
testcase_27 | AC | 144 ms
41,432 KB |
testcase_28 | AC | 138 ms
41,468 KB |
testcase_29 | AC | 137 ms
41,348 KB |
testcase_30 | AC | 134 ms
41,316 KB |
testcase_31 | AC | 136 ms
41,532 KB |
testcase_32 | AC | 132 ms
41,560 KB |
testcase_33 | AC | 134 ms
41,276 KB |
testcase_34 | AC | 145 ms
41,340 KB |
testcase_35 | AC | 143 ms
41,644 KB |
testcase_36 | AC | 140 ms
41,432 KB |
testcase_37 | AC | 142 ms
41,656 KB |
testcase_38 | AC | 140 ms
41,536 KB |
testcase_39 | AC | 141 ms
41,448 KB |
testcase_40 | AC | 142 ms
41,460 KB |
testcase_41 | AC | 144 ms
41,624 KB |
testcase_42 | AC | 141 ms
41,296 KB |
testcase_43 | AC | 132 ms
41,532 KB |
testcase_44 | AC | 147 ms
41,264 KB |
testcase_45 | AC | 157 ms
41,216 KB |
testcase_46 | AC | 143 ms
41,744 KB |
testcase_47 | AC | 148 ms
41,644 KB |
testcase_48 | AC | 147 ms
41,376 KB |
testcase_49 | AC | 146 ms
41,360 KB |
testcase_50 | AC | 145 ms
41,324 KB |
testcase_51 | AC | 142 ms
41,424 KB |
testcase_52 | AC | 143 ms
41,400 KB |
testcase_53 | AC | 141 ms
41,344 KB |
testcase_54 | AC | 144 ms
41,396 KB |
testcase_55 | AC | 150 ms
41,448 KB |
testcase_56 | AC | 142 ms
41,624 KB |
testcase_57 | AC | 144 ms
41,644 KB |
testcase_58 | AC | 146 ms
41,276 KB |
testcase_59 | AC | 142 ms
41,544 KB |
testcase_60 | AC | 141 ms
41,300 KB |
testcase_61 | AC | 141 ms
41,168 KB |
testcase_62 | AC | 147 ms
41,652 KB |
testcase_63 | AC | 146 ms
41,364 KB |
testcase_64 | AC | 141 ms
41,436 KB |
testcase_65 | AC | 141 ms
41,636 KB |
testcase_66 | AC | 139 ms
41,384 KB |
testcase_67 | AC | 143 ms
41,084 KB |
testcase_68 | AC | 152 ms
41,140 KB |
testcase_69 | AC | 152 ms
41,544 KB |
testcase_70 | AC | 153 ms
41,232 KB |
testcase_71 | AC | 145 ms
41,140 KB |
testcase_72 | AC | 137 ms
41,228 KB |
testcase_73 | AC | 150 ms
41,544 KB |
testcase_74 | AC | 147 ms
41,516 KB |
testcase_75 | AC | 138 ms
41,628 KB |
testcase_76 | AC | 136 ms
41,220 KB |
testcase_77 | AC | 141 ms
41,624 KB |
testcase_78 | AC | 144 ms
41,552 KB |
testcase_79 | AC | 143 ms
41,656 KB |
testcase_80 | AC | 137 ms
41,292 KB |
testcase_81 | AC | 144 ms
41,552 KB |
testcase_82 | AC | 141 ms
41,576 KB |
testcase_83 | AC | 139 ms
41,304 KB |
testcase_84 | AC | 143 ms
41,184 KB |
testcase_85 | AC | 143 ms
41,700 KB |
testcase_86 | AC | 144 ms
41,572 KB |
testcase_87 | AC | 137 ms
41,756 KB |
testcase_88 | AC | 145 ms
41,672 KB |
testcase_89 | AC | 143 ms
41,608 KB |
testcase_90 | AC | 143 ms
41,652 KB |
testcase_91 | AC | 143 ms
41,556 KB |
testcase_92 | AC | 140 ms
41,336 KB |
testcase_93 | AC | 138 ms
41,340 KB |
testcase_94 | AC | 140 ms
41,908 KB |
testcase_95 | AC | 144 ms
41,608 KB |
testcase_96 | AC | 151 ms
41,612 KB |
testcase_97 | AC | 140 ms
41,448 KB |
testcase_98 | AC | 147 ms
41,688 KB |
testcase_99 | AC | 147 ms
41,380 KB |
testcase_100 | AC | 144 ms
41,208 KB |
testcase_101 | AC | 148 ms
41,244 KB |
testcase_102 | AC | 145 ms
41,428 KB |
testcase_103 | AC | 141 ms
41,120 KB |
testcase_104 | AC | 148 ms
41,800 KB |
testcase_105 | AC | 142 ms
41,824 KB |
testcase_106 | AC | 142 ms
41,532 KB |
testcase_107 | AC | 141 ms
41,516 KB |
testcase_108 | AC | 141 ms
42,096 KB |
testcase_109 | AC | 140 ms
41,340 KB |
testcase_110 | AC | 142 ms
41,552 KB |
testcase_111 | AC | 139 ms
41,348 KB |
testcase_112 | AC | 141 ms
41,908 KB |
testcase_113 | AC | 148 ms
41,816 KB |
testcase_114 | AC | 145 ms
41,324 KB |
testcase_115 | AC | 141 ms
41,528 KB |
testcase_116 | AC | 142 ms
41,624 KB |
testcase_117 | AC | 142 ms
41,488 KB |
testcase_118 | AC | 147 ms
41,960 KB |
testcase_119 | AC | 146 ms
41,716 KB |
testcase_120 | AC | 148 ms
41,692 KB |
testcase_121 | AC | 143 ms
41,664 KB |
testcase_122 | AC | 139 ms
41,492 KB |
testcase_123 | AC | 143 ms
42,036 KB |
testcase_124 | AC | 140 ms
41,408 KB |
ソースコード
import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long a = sc.nextInt(); long b = sc.nextInt(); long c = sc.nextInt(); long d = b*b-4*a*c; if(a==0&&b==0&&c==0){ System.out.print(-1); } else if(a==0&&b==0){ System.out.print(0); } else if(a==0){ System.out.println(1); BigDecimal n1 = new BigDecimal(-c); BigDecimal n2 = new BigDecimal(b); System.out.println(n1.divide(n2,50, BigDecimal.ROUND_DOWN)); } else if(d<0){ System.out.println(0); } else if(d==0){ System.out.println(1); BigDecimal n1 = new BigDecimal(-b); BigDecimal n2 = new BigDecimal(2*a); System.out.println(n1.divide(n2,50, BigDecimal.ROUND_DOWN)); } else{ System.out.println(2); BigDecimal n1 = new BigDecimal(b*b-4*a*c); BigDecimal n2 = new BigDecimal(-b); BigDecimal n3 = new BigDecimal(2*a); BigDecimal n4 = sqrt(n1,50); if(a>0){ System.out.println((n2.subtract(n4)).divide(n3,50,BigDecimal.ROUND_DOWN)); System.out.println((n2.add(n4)).divide(n3,50,BigDecimal.ROUND_DOWN)); } else{ System.out.println((n2.add(n4)).divide(n3,50,BigDecimal.ROUND_DOWN)); System.out.println((n2.subtract(n4)).divide(n3,50,BigDecimal.ROUND_DOWN)); } } } public static BigDecimal sqrt(BigDecimal a, int scale){ BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64); if(scale < 17){ x = x.setScale(scale, BigDecimal.ROUND_HALF_EVEN); return x; } BigDecimal b2 = new BigDecimal(2); for(int tempScale = 16; tempScale < scale; tempScale *= 2){ x = x.subtract( x.multiply(x).subtract(a).divide( x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN)); } return x; } }