結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-02 03:33:34 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 942 bytes |
| コンパイル時間 | 2,641 ms |
| コンパイル使用メモリ | 78,660 KB |
| 実行使用メモリ | 59,848 KB |
| 最終ジャッジ日時 | 2024-11-28 02:33:22 |
| 合計ジャッジ時間 | 10,340 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 7 |
ソースコード
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));
}
}