結果
問題 | No.2420 Simple Problem |
ユーザー | hiromi_ayase |
提出日時 | 2023-08-12 15:06:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,122 ms / 2,000 ms |
コード長 | 2,460 bytes |
コンパイル時間 | 3,499 ms |
コンパイル使用メモリ | 76,928 KB |
実行使用メモリ | 61,488 KB |
最終ジャッジ日時 | 2023-09-02 08:15:42 |
合計ジャッジ時間 | 38,300 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,596 KB |
testcase_01 | AC | 603 ms
60,600 KB |
testcase_02 | AC | 127 ms
55,768 KB |
testcase_03 | AC | 375 ms
59,940 KB |
testcase_04 | AC | 785 ms
60,084 KB |
testcase_05 | AC | 751 ms
61,404 KB |
testcase_06 | AC | 1,089 ms
61,188 KB |
testcase_07 | AC | 1,092 ms
61,036 KB |
testcase_08 | AC | 1,066 ms
60,944 KB |
testcase_09 | AC | 862 ms
58,324 KB |
testcase_10 | AC | 854 ms
60,664 KB |
testcase_11 | AC | 1,100 ms
60,860 KB |
testcase_12 | AC | 1,068 ms
61,172 KB |
testcase_13 | AC | 1,062 ms
59,328 KB |
testcase_14 | AC | 1,059 ms
61,076 KB |
testcase_15 | AC | 844 ms
59,920 KB |
testcase_16 | AC | 1,122 ms
60,984 KB |
testcase_17 | AC | 1,072 ms
61,312 KB |
testcase_18 | AC | 1,081 ms
61,488 KB |
testcase_19 | AC | 1,074 ms
60,808 KB |
testcase_20 | AC | 844 ms
60,840 KB |
testcase_21 | AC | 841 ms
59,988 KB |
testcase_22 | AC | 842 ms
60,548 KB |
testcase_23 | AC | 1,065 ms
61,124 KB |
testcase_24 | AC | 848 ms
60,376 KB |
testcase_25 | AC | 1,073 ms
60,984 KB |
testcase_26 | AC | 56 ms
50,172 KB |
testcase_27 | AC | 805 ms
59,848 KB |
testcase_28 | AC | 809 ms
60,092 KB |
testcase_29 | AC | 885 ms
59,944 KB |
testcase_30 | AC | 820 ms
60,512 KB |
testcase_31 | AC | 816 ms
59,848 KB |
testcase_32 | AC | 47 ms
49,408 KB |
testcase_33 | AC | 608 ms
60,068 KB |
ソースコード
import java.util.*; import java.io.*; import java.math.BigInteger; @SuppressWarnings("unused") public class Main { private static void solve() { int n = ni(); for (int i = 0; i < n; i ++) { solve(ni(), ni()); } } private static void solve(long a, long b) { // a + b + 2sqrt(ab) < x^2 // x^2 - a - b > 2sqrt(ab) // (x^2 - a- b)^2 > 4ab long ok = (int)Math.sqrt(1e9) * 2 + 100; long ng = 0; var p = BigInteger.valueOf(4L * a * b); while (Math.abs(ok - ng) > 1) { long x = (ok + ng) / 2; long y = x * x - a - b; var q = BigInteger.valueOf(y).pow(2); if (y >= 0 && q.compareTo(p) > 0) { ok = x; } else { ng = x; } } out.println(ok); } public static void main(String[] args) { new Thread(null, new Runnable() { @Override public void run() { solve(); out.flush(); } }, "", 64000000).start(); } private static PrintWriter out = new PrintWriter(System.out); private static StringTokenizer tokenizer = null; private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 32768); public static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new java.util.StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private static double nd() { return Double.parseDouble(next()); } private static long nl() { return Long.parseLong(next()); } private static int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private static char[] ns() { return next().toCharArray(); } private static long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } private static int[][] ntable(int n, int m) { int[][] table = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[i][j] = ni(); } } return table; } private static int[][] nlist(int n, int m) { int[][] table = new int[m][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[j][i] = ni(); } } return table; } private static int ni() { return Integer.parseInt(next()); } }