Submission #2868353
Source Code Expand
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int Q = sc.nextInt(); long[] A = new long[Q+1]; long[] B = new long[Q+1]; for(int i=1;i<=Q;i++){ long num1 = sc.nextLong(); long num2 = sc.nextLong(); A[i] = Math.min(num1,num2); B[i] = Math.max(num1,num2); } for(int i=1;i<=Q;i++){ if(A[i]==B[i]){ System.out.println(2*(A[i]-1)); continue; } long ans1 = (A[i]-1)*2; long ans2 = 0; if(B[i]-A[i]<2) System.out.println(ans1); else{ long upper = A[i]*B[i]; long mid = (long) Math.floor(Math.sqrt(upper)); while(mid*mid>=upper) mid--; if(mid==A[i]) ans2 = 1; else{ ans2 += 2*(mid-A[i]+1)-1; if(mid*(mid+1)>=upper) ans2--; } System.out.println(ans2+ans1); } } } }
Submission Info
Submission Time | |
---|---|
Task | D - Worst Case |
User | AlbertZ |
Language | Java8 (OpenJDK 1.8.0) |
Score | 700 |
Code Size | 1153 Byte |
Status | AC |
Exec Time | 118 ms |
Memory | 20948 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, s1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 118 ms | 19156 KB |
02.txt | AC | 109 ms | 20948 KB |
03.txt | AC | 109 ms | 19540 KB |
04.txt | AC | 108 ms | 18900 KB |
05.txt | AC | 110 ms | 17236 KB |
06.txt | AC | 107 ms | 18772 KB |
07.txt | AC | 107 ms | 19796 KB |
08.txt | AC | 109 ms | 19796 KB |
09.txt | AC | 110 ms | 19028 KB |
10.txt | AC | 110 ms | 19156 KB |
11.txt | AC | 95 ms | 19412 KB |
s1.txt | AC | 94 ms | 19796 KB |