結果

問題 No.208 王将
ユーザー r.suzukir.suzuki
提出日時 2016-01-08 16:51:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 1,316 bytes
コンパイル時間 3,780 ms
コンパイル使用メモリ 77,740 KB
実行使用メモリ 41,668 KB
最終ジャッジ日時 2024-04-17 22:46:36
合計ジャッジ時間 7,089 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,496 KB
testcase_01 AC 126 ms
41,272 KB
testcase_02 AC 113 ms
41,624 KB
testcase_03 AC 122 ms
41,432 KB
testcase_04 AC 122 ms
41,668 KB
testcase_05 AC 111 ms
41,260 KB
testcase_06 AC 111 ms
41,536 KB
testcase_07 AC 125 ms
41,224 KB
testcase_08 AC 122 ms
41,420 KB
testcase_09 AC 122 ms
41,392 KB
testcase_10 AC 123 ms
41,596 KB
testcase_11 AC 122 ms
41,468 KB
testcase_12 AC 122 ms
41,116 KB
testcase_13 AC 122 ms
41,180 KB
testcase_14 AC 125 ms
41,656 KB
testcase_15 AC 131 ms
41,188 KB
testcase_16 AC 132 ms
41,580 KB
testcase_17 AC 129 ms
41,408 KB
testcase_18 AC 128 ms
41,400 KB
testcase_19 AC 128 ms
41,432 KB
testcase_20 AC 126 ms
41,368 KB
testcase_21 AC 128 ms
41,312 KB
testcase_22 AC 128 ms
41,128 KB
testcase_23 AC 126 ms
41,552 KB
testcase_24 AC 124 ms
41,172 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