結果

問題 No.467 隠されていたゲーム
ユーザー Grenache
提出日時 2016-12-17 12:01:30
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,421 bytes
コンパイル時間 4,083 ms
コンパイル使用メモリ 80,564 KB
実行使用メモリ 378,768 KB
最終ジャッジ日時 2024-12-14 04:20:17
合計ジャッジ時間 23,393 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 2 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder467 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] d = new int[n];
		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}
		Arrays.sort(d);
		int maxd = d[n - 1];

		int x = Math.abs(sc.nextInt());
		int y = Math.abs(sc.nextInt());
		int maxx = Math.max(x, y);

		if (maxx % maxd == 0) {
			pr.println(maxx / maxd);
			return;
		} else {
			int cnt = maxx / maxd;
			SortedSet<Long> hs = new TreeSet<>();
			Queue<Long> hstmp = new ArrayDeque<>();
			for (int e : d) {
				hs.add((long)e);
			}

			for (int i = 0; i <= cnt; i++) {
				if (hs.contains((long)(maxx - maxd * (cnt - i)))) {
					pr.println(cnt + 1);
					return;
				}

				hstmp.clear();
				for (long e : hs) {
					for (int j = 0, size = d.length; j < size - 1; j++) {
						int e1 = d[j];
						hstmp.add(e + e1);
					}
				}
				hs.addAll(hstmp);
			}

			if (x != y) {
				pr.println(Math.max(1, maxx / maxd) + 1);
			} else {
				pr.println(Math.max(1, maxx / maxd) + 1 + 1);
			}
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0