Submission #1043073
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { final int _intMax = Integer.MAX_VALUE; //=2147483647>10^9 final int _intMin = Integer.MIN_VALUE; final long _longMax = Long.MAX_VALUE; //=9223372036854775807L>10^18 final long _longMin = Long.MIN_VALUE; static boolean bElapsed = false; void solve() { int[] ia = readNums(); long x = ia[0]; long y = ia[1]; if (x == y) { pln("0"); return; } if (x == 0) { if (y > 0) { pln(y); return; } else { pln(-y+1); return; } } if (y == 0) { if (x > 0) { pln(x+1); return; } else { pln(-x); return; } } long sx = x >= 0 ? 1 : -1; long sy = y >= 0 ? 1 : -1; if (sx == sy) { if (y == 0) { pln(x+1); } else if (x <= y) { pln(y-x); } else { pln(x-y+2); } } else if (sx < 0) { x = -x; if (x == y) { pln("1"); } else if (y == 0) { pln(x); } else if (x < y) { pln(y-x+1); } else { pln(x-y+1); } } else if (sy < 0) { y = -y; if (x == y) { pln("1"); } else if (x == 0) { pln(y); } else if (x < y) { pln(y-x+1); } else { pln(x-y+1); } } } long ceil2pow(long n) { if (n == 0) return 1; n--; n |= (n >>> 1); n |= (n >>> 2); n |= (n >>> 4); n |= (n >>> 8); n |= (n >>> 16); n++; return n; /* long pow = 1; while (pow < n) pow <<= 1; return pow; */ } int gcd(int a, int b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } long sqrt(long n) { return (long)Math.sqrt(n); } long pow(long n, long p) { return (long)Math.pow(n, p); } long pow_mod(long n, long p, long m) { if (p == 0) return 1; else if (p % 2 == 1) return pow_mod(n, p-1, m) * n % m; long sum = pow_mod(n, p/2, m); return sum * sum % m; } int pint(String s) { return Integer.parseInt(s); } long plong(String s) { return Long.parseLong(s); } String readLine() { try { return _in.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } int readNum() { String line = readLine(); return pint(line); } String[] readFlds() { String line = readLine(); return line.split(" "); } int[] readNums() { String[] flds = readFlds(); int[] nums = new int[flds.length]; for (int i=0; i<flds.length; i++) { nums[i] = pint(flds[i]); } return nums; } void p(char c) { _out.print(c); } void pln(char c) { _out.println(c); } void p(double d) { _out.print(d); } void pln(double d) { _out.println(d); } void p(long l) { _out.print(l); } void pln(long l) { _out.println(l); } void p(String s) { _out.print(s); } void pln(String s) { _out.println(s); } static BufferedReader _in; static PrintWriter _out; public static void main(String[] args) { long start = System.currentTimeMillis(); _in = new BufferedReader(new InputStreamReader(System.in)); _out = new PrintWriter(System.out); new Main().solve(); _out.flush(); long end = System.currentTimeMillis(); if (bElapsed) { System.err.println((end-start) + "ms"); } } }
Submission Info
Submission Time | |
---|---|
Task | A - Simple Calculator |
User | hiuchida |
Language | Java8 (OpenJDK 1.8.0) |
Score | 300 |
Code Size | 3334 Byte |
Status | AC |
Exec Time | 97 ms |
Memory | 8276 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 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 | 97 ms | 8148 KB |
0_01.txt | AC | 97 ms | 8144 KB |
0_02.txt | AC | 95 ms | 8144 KB |
1_00.txt | AC | 94 ms | 8272 KB |
1_01.txt | AC | 95 ms | 8148 KB |
1_02.txt | AC | 97 ms | 8144 KB |
1_03.txt | AC | 96 ms | 8144 KB |
1_04.txt | AC | 95 ms | 8148 KB |
1_05.txt | AC | 95 ms | 8276 KB |
1_06.txt | AC | 95 ms | 8276 KB |
1_07.txt | AC | 95 ms | 8272 KB |
1_08.txt | AC | 96 ms | 8144 KB |
1_09.txt | AC | 95 ms | 8276 KB |
1_10.txt | AC | 96 ms | 8148 KB |