結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2017-12-02 00:14:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,196 bytes |
| コンパイル時間 | 3,212 ms |
| コンパイル使用メモリ | 80,284 KB |
| 実行使用メモリ | 64,360 KB |
| 最終ジャッジ日時 | 2024-11-28 00:04:26 |
| 合計ジャッジ時間 | 9,983 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 7 |
ソースコード
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeSet;
public class Main {
public static long MOD = 1000000007;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int n = sc.nextInt();
TreeSet<Long> set = new TreeSet<Long>();
for(int i = 0; i < n; i++){ set.add(sc.nextLong()); }
final long x = sc.nextLong();
final long y = sc.nextLong();
final long d = Math.abs(x) + Math.abs(y);
ArrayList<Long> arr = new ArrayList<>(set);
if(d == 0){
System.out.println(0);
return;
}
for(final long s : arr){
if(d == s){
System.out.println(1);
return;
}
}
for(int i = 0; i < arr.size(); i++){
final long s = arr.get(i);
if(d > s){
final long rest = d - s;
final long pos = Collections.binarySearch(arr, rest);
if(pos >= 0){
System.out.println(2);
return;
}
}else{
final long rest = s - d;
final long pos = Collections.binarySearch(arr, rest);
if(pos >= 0){
System.out.println(2);
return;
}
}
}
System.out.println(-1);
}
}
uafr_cs