結果

問題 No.467 隠されていたゲーム
ユーザー shinwisteriashinwisteria
提出日時 2017-03-24 18:38:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,302 bytes
コンパイル時間 3,786 ms
コンパイル使用メモリ 76,304 KB
実行使用メモリ 59,548 KB
最終ジャッジ日時 2023-09-20 06:05:07
合計ジャッジ時間 11,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,812 KB
testcase_01 AC 128 ms
55,840 KB
testcase_02 AC 128 ms
55,612 KB
testcase_03 AC 128 ms
56,036 KB
testcase_04 AC 124 ms
55,736 KB
testcase_05 AC 134 ms
55,856 KB
testcase_06 AC 130 ms
55,828 KB
testcase_07 AC 126 ms
55,852 KB
testcase_08 AC 130 ms
55,768 KB
testcase_09 AC 133 ms
55,632 KB
testcase_10 AC 128 ms
55,996 KB
testcase_11 AC 128 ms
55,856 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeSet;

public class HiddenGame {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int[] d = new int[N];
		for(int i = 0;i < N;i++){
			d[i] = s.nextInt();
		}
		Arrays.sort(d);
		int goalx = s.nextInt(),goaly = s.nextInt();
		s.close();
		
		int goal = Integer.max(Math.abs(goalx), Math.abs(goaly));
		int count = 0;
		if(goal/d[N-1] > 10000000){
			count = goal/d[N-1]-2;
			goal = goal%d[N-1]+2;
		}
		
		TreeSet<Integer> T1 = new TreeSet<>();
		TreeSet<Integer> T2 = new TreeSet<>();
		Queue<Integer> REST = new ArrayDeque<>();
		REST.add(goal);
		
		for(;;){
			int rest = REST.poll();
			if(rest == 0){
				break;
			}else if(rest < d[0]){
				count +=2;
				break;
			}
			T1.clear();
			for(int i : d){
				T1.add(Math.abs(rest-i));
			}
			for(int i:T1){
				for(int j:d){
					T2.add(Math.abs(i-j));
				}
			}
			if(T2.contains(0)){
				count += 2;
				break;
			}else if(T1.contains(0)){
				count += 1;
				break;
			}else if(T1.first() == T2.first()){
				count = -1;
			}
			REST.clear();
			REST.addAll(T1);
			T1 = new TreeSet<Integer>(T2);
			T2.clear();
			count++;
		}
		System.out.println(count);
	}
}
0