結果

問題 No.602 隠されていたゲーム2
ユーザー uafr_csuafr_cs
提出日時 2017-12-02 01:11:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,720 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 79,476 KB
実行使用メモリ 72,208 KB
最終ジャッジ日時 2024-05-06 00:31:17
合計ジャッジ時間 9,095 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
40,004 KB
testcase_01 AC 112 ms
41,292 KB
testcase_02 AC 108 ms
41,084 KB
testcase_03 AC 107 ms
40,852 KB
testcase_04 AC 99 ms
40,664 KB
testcase_05 WA -
testcase_06 AC 101 ms
40,340 KB
testcase_07 AC 113 ms
41,024 KB
testcase_08 AC 112 ms
40,084 KB
testcase_09 AC 99 ms
40,096 KB
testcase_10 WA -
testcase_11 AC 109 ms
41,400 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 97 ms
39,580 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 763 ms
63,684 KB
testcase_23 AC 614 ms
62,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0