Submission #2868291
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 if (B[i]-A[i]==2) System.out.println(ans1+1); else{ long upper = A[i]*B[i]; long mid = (long) Math.floor(Math.sqrt(upper-1)); 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 | 0 |
Code Size | 1080 Byte |
Status | WA |
Exec Time | 109 ms |
Memory | 23508 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 109 ms | 21716 KB |
02.txt | AC | 108 ms | 21972 KB |
03.txt | WA | 109 ms | 19156 KB |
04.txt | AC | 107 ms | 19284 KB |
05.txt | AC | 108 ms | 19924 KB |
06.txt | AC | 106 ms | 21844 KB |
07.txt | WA | 108 ms | 23508 KB |
08.txt | WA | 109 ms | 20820 KB |
09.txt | WA | 108 ms | 21844 KB |
10.txt | WA | 109 ms | 19028 KB |
11.txt | AC | 94 ms | 19284 KB |
s1.txt | AC | 95 ms | 21204 KB |