AtCoder Grand Contest 008

Submission #1358171

Source codeソースコード

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            long x = Long.parseLong(strArr[0]);
            long y = Long.parseLong(strArr[1]);
            if (x > 0) {
                if (y > 0) {
                    if (y >= x) {
                        System.out.println(y - x);
                    } else {
                        System.out.println((-1 * y) - (-1 * x) + 2);
                    }
                } else if (y < 0) {
                    if (x > Math.abs(y)) {
                        System.out.println(y - (-1 * x) + 1);
                    } else {
                        long diff = Math.abs(y) - x;
                        System.out.println(diff + 1);
                    }
                } else {
                    System.out.println(y - (-1 * x) + 1);
                }
            } else if (x < 0) {
                if (y > 0) {
                    if (Math.abs(x) > y) {
                        System.out.println((-1 * y) - x + 1);
                    } else {
                        long diff = y - (-1 * x);
                        System.out.println(diff + 1);
                    }
                } else if (y < 0){
                    if (Math.abs(x) >= Math.abs(y)) {
                        System.out.println(y - x);
                    } else {
                        long diff = (-1 * y) - (-1 * x);
                        System.out.println(diff + 2);
                    }
                } else {
                    System.out.println(y - x);
                }
            } else {
                if (y > 0) {
                    System.out.println(y - x);
                } else if (y < 0) {
                    System.out.println(Math.abs(y) - x + 1);
                } else {
                    System.out.println(0);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}

Submission

Task問題 A - Simple Calculator
User nameユーザ名 山崎裕昭
Created time投稿日時
Language言語 Java8 (OpenJDK 1.8.0)
Status状態 AC
Score得点 300
Source lengthソースコード長 2296 Byte
File nameファイル名
Exec time実行時間 70 ms
Memory usageメモリ使用量 22484 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
All 300 / 300 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 70 ms 20692 KB
0_01.txt AC 70 ms 16852 KB
0_02.txt AC 69 ms 18004 KB
1_00.txt AC 69 ms 19028 KB
1_01.txt AC 70 ms 22484 KB
1_02.txt AC 68 ms 19284 KB
1_03.txt AC 67 ms 17492 KB
1_04.txt AC 70 ms 19284 KB
1_05.txt AC 68 ms 19412 KB
1_06.txt AC 69 ms 18388 KB
1_07.txt AC 68 ms 21204 KB
1_08.txt AC 69 ms 21204 KB
1_09.txt AC 70 ms 18772 KB
1_10.txt AC 70 ms 18644 KB