結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2017-12-02 01:11:15 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,720 bytes |
| コンパイル時間 | 1,893 ms |
| コンパイル使用メモリ | 79,260 KB |
| 実行使用メモリ | 62,700 KB |
| 最終ジャッジ日時 | 2024-11-28 02:01:51 |
| 合計ジャッジ時間 | 8,937 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 11 |
ソースコード
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 void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int n = sc.nextInt();
long[] array = new long[n];
for(int i = 0; i < n; i++){
array[i] = sc.nextLong();
}
TreeSet<Long> odds = new TreeSet<Long>();
TreeSet<Long> evens = new TreeSet<Long>();
for(int i = 0; i < n; i++){
if(array[i] % 2 == 0){
evens.add(array[i]);
}else{
odds.add(array[i]);
}
}
final long x = sc.nextLong();
final long y = sc.nextLong();
final long d = Math.abs(x) + Math.abs(y);
if(d == 0){
System.out.println(0);
return;
}
if(d % 2 == 0){ // (odd, odd) or (even, even)
if(evens.ceiling(d) != null){
System.out.println(1);
return;
}
for(final long s : evens){
final long diff = Math.abs(d - s);
if(evens.ceiling(diff) != null){
System.out.println(2);
return;
}
}
for(final long s : odds){
final long diff = Math.abs(d - s);
if(odds.ceiling(diff) != null){
System.out.println(2);
return;
}
}
}else{ // (odd, even) or (even, odd)
if(odds.ceiling(d) != null){
System.out.println(1);
return;
}
for(final long s : evens){
final long diff = Math.abs(d - s);
if(odds.ceiling(diff) != null){
System.out.println(2);
return;
}
}
for(final long s : odds){
final long diff = Math.abs(d - s);
if(evens.ceiling(diff) != null){
System.out.println(2);
return;
}
}
}
System.out.println(-1);
}
}
uafr_cs