結果

問題 No.208 王将
ユーザー r.suzukir.suzuki
提出日時 2016-01-08 16:51:17
言語 Java19
(openjdk 21)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 1,316 bytes
コンパイル時間 3,101 ms
コンパイル使用メモリ 74,020 KB
実行使用メモリ 56,576 KB
最終ジャッジ日時 2023-07-30 21:29:52
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,172 KB
testcase_01 AC 121 ms
56,184 KB
testcase_02 AC 121 ms
55,752 KB
testcase_03 AC 121 ms
56,196 KB
testcase_04 AC 124 ms
55,460 KB
testcase_05 AC 125 ms
55,820 KB
testcase_06 AC 122 ms
55,812 KB
testcase_07 AC 121 ms
56,308 KB
testcase_08 AC 120 ms
56,576 KB
testcase_09 AC 120 ms
55,948 KB
testcase_10 AC 120 ms
56,108 KB
testcase_11 AC 120 ms
56,108 KB
testcase_12 AC 121 ms
55,872 KB
testcase_13 AC 120 ms
55,876 KB
testcase_14 AC 120 ms
55,812 KB
testcase_15 AC 122 ms
56,020 KB
testcase_16 AC 120 ms
55,812 KB
testcase_17 AC 126 ms
55,716 KB
testcase_18 AC 120 ms
55,764 KB
testcase_19 AC 120 ms
55,648 KB
testcase_20 AC 120 ms
55,884 KB
testcase_21 AC 120 ms
55,712 KB
testcase_22 AC 120 ms
55,712 KB
testcase_23 AC 124 ms
55,760 KB
testcase_24 AC 120 ms
56,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class No_208 {
	static boolean straight(int x, int y) {
		if (x == 0 || y == 0 || Math.abs(x) == Math.abs(y)) {
			return true;
		} else {
			return false;
		}
	}

	static String direction(int x, int y) {
		if (x == 0) {
			if (y > 0)
				return "N";
			else
				return "S";
		} else if (y == 0) {
			if (x > 0)
				return "E";
			else
				return "W";
		} else if (x == y) {
			if (x > 0)
				return "NE";
			else
				return "SW";
		} else {
			if (x > y)
				return "SE";
			else
				return "NW";
		}
	}

	static boolean inTheWay(String dir, int Y, int fuY) {
		switch (dir) {
		case "N":
		case "E":
		case "S":
		case "W":
			return false;
		case "NE":
		case "NW":
			if (Y > fuY)
				return true;
			else
				return false;
		case "SE":
		case "SW":
			if (Y < fuY)
				return true;
			else
				return false;
		}
		return false;
	}

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int X, Y, fuX, fuY;
		X = sc.nextInt();
		Y = sc.nextInt();
		fuX = sc.nextInt();
		fuY = sc.nextInt();

		int step = Math.max(X, Y);

		if (straight(X, Y) && straight(fuX, fuY)) {
			String dir = direction(X, Y);
			if (dir.equals(direction(fuX, fuY))) {
				if (inTheWay(dir, Y, fuY)) {
					step += 1;
				}
			}
		}
		System.out.println(step);
		sc.close();

	}

}
0