Submission #1042131
Source Code Expand
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int y = sc.nextInt(); int x = sc.nextInt(); System.out.println(calc(x, y)); } private static int calc(int x, int y) { if (x == y) { return 0; } else if (y >= 0 && y < x) { return x - y; } else if (x >= 0 && y > x) { return y - x + 2; } else if (y <= 0 && x < y) { return y - x + 2; } else if (x <= 0 && y < x) { return x - y; } else if (x >= 0 && y <= 0) { if (Math.abs(x) > Math.abs(y)) { return x + y + 1; } else { return -y - x + 1; } } else if (x <= 0 && y >= 0) { if (Math.abs(x) > Math.abs(y)) { return -x - y + 1; } else { return x + y + 1; } } return 0; } private static void test() { assert calc(10, 20) == 10 : "10, 20"; assert calc(10, -10) == 1 : "10, -10"; assert calc(-10, -20) == 12 : "-10, -20"; } }
Submission Info
Submission Time | |
---|---|
Task | A - Simple Calculator |
User | bdgaqh1889 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 1230 Byte |
Status | WA |
Exec Time | 151 ms |
Memory | 10196 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 145 ms | 10196 KB |
0_01.txt | AC | 123 ms | 9676 KB |
0_02.txt | AC | 128 ms | 9684 KB |
1_00.txt | AC | 127 ms | 9812 KB |
1_01.txt | AC | 128 ms | 9684 KB |
1_02.txt | WA | 122 ms | 9680 KB |
1_03.txt | WA | 151 ms | 9684 KB |
1_04.txt | AC | 122 ms | 9680 KB |
1_05.txt | AC | 127 ms | 9680 KB |
1_06.txt | AC | 128 ms | 9676 KB |
1_07.txt | AC | 124 ms | 9684 KB |
1_08.txt | AC | 122 ms | 9808 KB |
1_09.txt | AC | 128 ms | 9684 KB |
1_10.txt | AC | 122 ms | 9680 KB |