結果

問題 No.602 隠されていたゲーム2
ユーザー uafr_csuafr_cs
提出日時 2017-12-03 16:49:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,483 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 78,020 KB
実行使用メモリ 49,740 KB
最終ジャッジ日時 2024-05-06 09:06:06
合計ジャッジ時間 9,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
40,904 KB
testcase_01 AC 126 ms
41,100 KB
testcase_02 AC 113 ms
40,252 KB
testcase_03 AC 130 ms
41,372 KB
testcase_04 AC 113 ms
39,940 KB
testcase_05 AC 115 ms
40,052 KB
testcase_06 AC 114 ms
40,080 KB
testcase_07 AC 126 ms
41,104 KB
testcase_08 AC 126 ms
41,272 KB
testcase_09 AC 125 ms
41,104 KB
testcase_10 AC 114 ms
39,948 KB
testcase_11 AC 127 ms
41,100 KB
testcase_12 AC 126 ms
41,764 KB
testcase_13 AC 113 ms
40,196 KB
testcase_14 AC 125 ms
41,096 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 413 ms
48,252 KB
testcase_18 AC 577 ms
48,792 KB
testcase_19 AC 631 ms
48,712 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 653 ms
48,864 KB
testcase_23 AC 598 ms
49,740 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 {
	
	// ずっと "マンハッタン距離 D だけ移動できる と誤読していた"
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		long[] array = new long[n];
		
		long odd_max = 0, even_max = 0;
		for(int i = 0; i < n; i++){
			array[i] = sc.nextLong();
			
			if(array[i] % 2 == 0){
				even_max = Math.max(even_max, array[i]);
			}else{
				odd_max = Math.max(odd_max, 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;
		}
		
		for(final long s : array){
			if(s == d){
				System.out.println(1);
				return;
			}
		}
		
		if(odd_max == 0){
			final long d_even_max = even_max * 2;
			if(d % 2 == 1){
				System.out.println(-1); return;
			}else if(d <= d_even_max){
				System.out.println(2); return;
			}else{
				System.out.println(-1); return;
			}
		}else{
			final long d_even_max = Math.max(odd_max * 2, even_max * 2);
			final long d_odd_max = odd_max + even_max;
			
			if(d % 2 == 0 && d <= d_even_max){
				System.out.println(2); return;
			}else if(d % 2 == 1 && d <= d_odd_max){
				System.out.println(2); return;
			}else{
				System.out.println(-1); return;
			}
		}
	}
}
0