結果
問題 | No.550 夏休みの思い出(1) |
ユーザー | Grenache |
提出日時 | 2017-07-28 23:23:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 787 ms / 2,000 ms |
コード長 | 2,473 bytes |
コンパイル時間 | 4,061 ms |
コンパイル使用メモリ | 81,748 KB |
実行使用メモリ | 61,632 KB |
最終ジャッジ日時 | 2024-10-11 05:33:11 |
合計ジャッジ時間 | 24,596 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 139 ms
54,032 KB |
testcase_01 | AC | 770 ms
61,380 KB |
testcase_02 | AC | 776 ms
61,524 KB |
testcase_03 | AC | 768 ms
61,476 KB |
testcase_04 | AC | 757 ms
61,380 KB |
testcase_05 | AC | 774 ms
61,436 KB |
testcase_06 | AC | 758 ms
61,472 KB |
testcase_07 | AC | 787 ms
61,444 KB |
testcase_08 | AC | 765 ms
61,344 KB |
testcase_09 | AC | 138 ms
54,264 KB |
testcase_10 | AC | 138 ms
53,960 KB |
testcase_11 | AC | 141 ms
54,212 KB |
testcase_12 | AC | 139 ms
54,256 KB |
testcase_13 | AC | 138 ms
54,060 KB |
testcase_14 | AC | 127 ms
53,040 KB |
testcase_15 | AC | 137 ms
53,964 KB |
testcase_16 | AC | 135 ms
53,968 KB |
testcase_17 | AC | 137 ms
54,232 KB |
testcase_18 | AC | 141 ms
54,076 KB |
testcase_19 | AC | 137 ms
54,088 KB |
testcase_20 | AC | 137 ms
54,216 KB |
testcase_21 | AC | 137 ms
54,004 KB |
testcase_22 | AC | 619 ms
61,632 KB |
testcase_23 | AC | 468 ms
61,416 KB |
testcase_24 | AC | 520 ms
61,468 KB |
testcase_25 | AC | 563 ms
61,556 KB |
testcase_26 | AC | 518 ms
61,512 KB |
testcase_27 | AC | 493 ms
61,492 KB |
testcase_28 | AC | 482 ms
61,480 KB |
testcase_29 | AC | 360 ms
60,008 KB |
testcase_30 | AC | 688 ms
61,392 KB |
testcase_31 | AC | 180 ms
57,032 KB |
testcase_32 | AC | 171 ms
57,020 KB |
testcase_33 | AC | 197 ms
57,132 KB |
testcase_34 | AC | 177 ms
56,388 KB |
testcase_35 | AC | 176 ms
57,024 KB |
testcase_36 | AC | 182 ms
56,876 KB |
testcase_37 | AC | 172 ms
56,892 KB |
testcase_38 | AC | 183 ms
57,084 KB |
testcase_39 | AC | 157 ms
53,952 KB |
testcase_40 | AC | 330 ms
59,156 KB |
testcase_41 | AC | 304 ms
57,708 KB |
testcase_42 | AC | 334 ms
59,316 KB |
testcase_43 | AC | 269 ms
57,496 KB |
testcase_44 | AC | 285 ms
57,712 KB |
testcase_45 | AC | 271 ms
57,260 KB |
testcase_46 | AC | 307 ms
58,352 KB |
testcase_47 | AC | 201 ms
56,636 KB |
testcase_48 | AC | 146 ms
53,976 KB |
testcase_49 | AC | 136 ms
54,216 KB |
testcase_50 | AC | 136 ms
54,156 KB |
testcase_51 | AC | 170 ms
56,356 KB |
testcase_52 | AC | 267 ms
57,340 KB |
testcase_53 | AC | 264 ms
57,340 KB |
testcase_54 | AC | 264 ms
57,564 KB |
testcase_55 | AC | 265 ms
57,368 KB |
testcase_56 | AC | 269 ms
57,568 KB |
testcase_57 | AC | 271 ms
57,384 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); } } }