結果
問題 | No.550 夏休みの思い出(1) |
ユーザー | Grenache |
提出日時 | 2017-07-28 23:23:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 788 ms / 2,000 ms |
コード長 | 2,473 bytes |
コンパイル時間 | 4,308 ms |
コンパイル使用メモリ | 82,480 KB |
実行使用メモリ | 50,564 KB |
最終ジャッジ日時 | 2024-04-19 13:10:36 |
合計ジャッジ時間 | 21,653 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 116 ms
41,264 KB |
testcase_01 | AC | 654 ms
50,208 KB |
testcase_02 | AC | 683 ms
50,520 KB |
testcase_03 | AC | 788 ms
50,248 KB |
testcase_04 | AC | 679 ms
50,456 KB |
testcase_05 | AC | 669 ms
50,312 KB |
testcase_06 | AC | 661 ms
50,492 KB |
testcase_07 | AC | 679 ms
50,316 KB |
testcase_08 | AC | 691 ms
50,332 KB |
testcase_09 | AC | 120 ms
41,296 KB |
testcase_10 | AC | 117 ms
41,816 KB |
testcase_11 | AC | 124 ms
41,828 KB |
testcase_12 | AC | 120 ms
41,412 KB |
testcase_13 | AC | 109 ms
41,568 KB |
testcase_14 | AC | 122 ms
41,564 KB |
testcase_15 | AC | 124 ms
41,892 KB |
testcase_16 | AC | 121 ms
41,708 KB |
testcase_17 | AC | 117 ms
41,864 KB |
testcase_18 | AC | 121 ms
41,724 KB |
testcase_19 | AC | 118 ms
41,412 KB |
testcase_20 | AC | 126 ms
41,792 KB |
testcase_21 | AC | 128 ms
41,572 KB |
testcase_22 | AC | 537 ms
50,396 KB |
testcase_23 | AC | 400 ms
50,564 KB |
testcase_24 | AC | 449 ms
50,404 KB |
testcase_25 | AC | 482 ms
50,236 KB |
testcase_26 | AC | 459 ms
50,456 KB |
testcase_27 | AC | 426 ms
50,344 KB |
testcase_28 | AC | 420 ms
50,280 KB |
testcase_29 | AC | 280 ms
49,308 KB |
testcase_30 | AC | 605 ms
50,152 KB |
testcase_31 | AC | 146 ms
45,404 KB |
testcase_32 | AC | 151 ms
45,600 KB |
testcase_33 | AC | 162 ms
45,640 KB |
testcase_34 | AC | 146 ms
44,120 KB |
testcase_35 | AC | 157 ms
45,956 KB |
testcase_36 | AC | 152 ms
45,472 KB |
testcase_37 | AC | 148 ms
45,624 KB |
testcase_38 | AC | 151 ms
45,540 KB |
testcase_39 | AC | 125 ms
42,364 KB |
testcase_40 | AC | 267 ms
48,648 KB |
testcase_41 | AC | 254 ms
46,960 KB |
testcase_42 | AC | 274 ms
49,168 KB |
testcase_43 | AC | 236 ms
46,696 KB |
testcase_44 | AC | 255 ms
46,356 KB |
testcase_45 | AC | 222 ms
46,196 KB |
testcase_46 | AC | 256 ms
47,224 KB |
testcase_47 | AC | 174 ms
45,904 KB |
testcase_48 | AC | 116 ms
42,808 KB |
testcase_49 | AC | 117 ms
41,764 KB |
testcase_50 | AC | 119 ms
41,732 KB |
testcase_51 | AC | 146 ms
43,192 KB |
testcase_52 | AC | 225 ms
46,432 KB |
testcase_53 | AC | 233 ms
46,244 KB |
testcase_54 | AC | 241 ms
46,184 KB |
testcase_55 | AC | 228 ms
46,092 KB |
testcase_56 | AC | 232 ms
46,412 KB |
testcase_57 | AC | 231 ms
46,284 KB |
ソースコード
import java.io.*; import java.math.*; import java.util.*; public class Main_yukicoder550 { private static Scanner sc; private static Printer pr; private static void solve() { long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong(); long d; long e; List<Long> ans = new ArrayList<>(3); if (c == 0) { ans.add(0L); d = a; e = b; } else { for (long x = 1; x <= 1_000_000; x++) { if (isOK(x, a, b, c)) { ans.add(x); break; } if (isOK(-x, a, b, c)) { ans.add(-x); break; } } e = -c / ans.get(0); d = a + ans.get(0); } BigInteger bd = BigInteger.valueOf(d); BigInteger be = BigInteger.valueOf(e); BigInteger dd = bd.multiply(bd).subtract(BigInteger.valueOf(4).multiply(be)); BigInteger[] sqrtdd = sqrt(dd); BigInteger ans1 = bd.negate().add(sqrtdd[0]).divide(BigInteger.valueOf(2)); BigInteger ans2 = bd.negate().subtract(sqrtdd[0]).divide(BigInteger.valueOf(2)); ans.add(ans1.longValue()); ans.add(ans2.longValue()); Collections.sort(ans); for (int i = 0; i < 3; i++) { if (i > 0) { pr.print(' '); } pr.print(ans.get(i)); } pr.println(); } private static boolean isOK(long x, long a, long b, long c) { BigInteger bx = BigInteger.valueOf(x); BigInteger f = bx.multiply(bx).multiply(bx).add(bx.multiply(bx).multiply(BigInteger.valueOf(a)).add(bx.multiply(BigInteger.valueOf(b))).add(BigInteger.valueOf(c))); return f.compareTo(BigInteger.ZERO) == 0; } private static BigInteger[] sqrt(BigInteger x) { BigInteger number = x; BigInteger a = BigInteger.ONE; BigInteger b = number.shiftRight(5).add(BigInteger.valueOf(8)); while (b.compareTo(a) >= 0) { BigInteger mid = a.add(b).shiftRight(1); if (mid.multiply(mid).compareTo(number) > 0) { b = mid.subtract(BigInteger.ONE); } else { a = mid.add(BigInteger.ONE); } } BigInteger sqrtNumber = a.subtract(BigInteger.ONE); BigInteger remainderNumber = number.subtract(sqrtNumber.multiply(sqrtNumber)); BigInteger[] ret = new BigInteger[2]; ret[0] = sqrtNumber; ret[1] = remainderNumber; return ret; } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }