結果

問題 No.602 隠されていたゲーム2
ユーザー 37zigen37zigen
提出日時 2017-12-02 03:33:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 942 bytes
コンパイル時間 2,970 ms
コンパイル使用メモリ 79,216 KB
実行使用メモリ 59,340 KB
最終ジャッジ日時 2024-05-06 00:52:23
合計ジャッジ時間 9,776 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
40,184 KB
testcase_01 AC 110 ms
41,132 KB
testcase_02 AC 104 ms
40,304 KB
testcase_03 AC 101 ms
40,004 KB
testcase_04 AC 122 ms
41,248 KB
testcase_05 AC 110 ms
40,184 KB
testcase_06 AC 117 ms
41,208 KB
testcase_07 AC 112 ms
41,156 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 110 ms
41,176 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 112 ms
40,992 KB
testcase_16 AC 272 ms
46,580 KB
testcase_17 AC 403 ms
48,680 KB
testcase_18 AC 605 ms
53,760 KB
testcase_19 AC 635 ms
57,340 KB
testcase_20 AC 519 ms
56,024 KB
testcase_21 AC 527 ms
55,492 KB
testcase_22 WA -
testcase_23 AC 566 ms
59,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		long[] d;
		long x, y;
		n = sc.nextInt();
		d = new long[n];
		for (int i = 0; i < n; ++i)
			d[i] = sc.nextLong();
		x = sc.nextLong();
		y = sc.nextLong();
		System.out.println(solve(n, d, x, y));
	}

	static int solve(int n, long[] d, long x, long y) {
		x = Math.abs(x);
		y = Math.abs(y);
		if (x == 0 && y == 0) {
			return 0;
		}
		for (int i = 0; i < n; ++i) {
			if (d[i] == x + y) {
				return 1;
			}
		}
		HashSet<Long> set = new HashSet();
		for (int i = 0; i < n; ++i) {
			set.add(d[i]);
		}

		for (int i = 0; i < n; ++i) {
			if (!set.contains(x + y - d[i]) && !set.contains(x + y + d[i]))
				continue;
			return 2;
		}
		return -1;

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0