結果

問題 No.467 隠されていたゲーム
ユーザー GrenacheGrenache
提出日時 2016-12-17 23:46:01
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,703 bytes
コンパイル時間 4,112 ms
コンパイル使用メモリ 80,464 KB
実行使用メモリ 54,668 KB
最終ジャッジ日時 2024-05-08 04:14:55
合計ジャッジ時間 9,224 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 144 ms
54,184 KB
testcase_02 AC 141 ms
54,436 KB
testcase_03 AC 139 ms
54,376 KB
testcase_04 AC 142 ms
54,128 KB
testcase_05 AC 143 ms
54,500 KB
testcase_06 AC 139 ms
53,868 KB
testcase_07 AC 142 ms
54,300 KB
testcase_08 AC 143 ms
54,348 KB
testcase_09 AC 143 ms
54,220 KB
testcase_10 AC 143 ms
54,376 KB
testcase_11 AC 143 ms
54,100 KB
testcase_12 AC 142 ms
54,296 KB
testcase_13 AC 142 ms
54,216 KB
testcase_14 AC 145 ms
54,172 KB
testcase_15 AC 145 ms
54,280 KB
testcase_16 AC 141 ms
54,312 KB
testcase_17 AC 142 ms
54,520 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 147 ms
54,340 KB
testcase_24 AC 143 ms
54,564 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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 {
			if (d.length > 1) {
				int cnt = maxx / maxd;
				SortedSet<Long> hs = new TreeSet<>();
				Queue<Long> hstmp = new ArrayDeque<>();
				for (int j = 0, size = d.length; j < size - 1; j++) {
					hs.add((long)d[j]);
				}

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

					if (hs.last() + d[n - 2] < maxx - maxd * (cnt - i)) {
						break;
					}

					hstmp.clear();
					hstmp.addAll(hs.headSet((long)(maxx - maxd * (cnt - i - 1))));
					hs.removeAll(hstmp);

					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