結果

問題 No.1816 MUL-DIV Game
ユーザー ks2mks2m
提出日時 2022-01-21 22:07:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,097 ms / 2,000 ms
コード長 2,001 bytes
コンパイル時間 2,386 ms
コンパイル使用メモリ 81,956 KB
実行使用メモリ 71,456 KB
最終ジャッジ日時 2023-08-17 06:11:20
合計ジャッジ時間 20,129 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,524 KB
testcase_01 AC 127 ms
55,904 KB
testcase_02 AC 125 ms
56,048 KB
testcase_03 AC 126 ms
56,204 KB
testcase_04 AC 126 ms
56,160 KB
testcase_05 AC 125 ms
55,848 KB
testcase_06 AC 128 ms
56,048 KB
testcase_07 AC 127 ms
56,080 KB
testcase_08 AC 128 ms
55,988 KB
testcase_09 AC 364 ms
60,840 KB
testcase_10 AC 694 ms
62,700 KB
testcase_11 AC 623 ms
63,144 KB
testcase_12 AC 551 ms
64,352 KB
testcase_13 AC 866 ms
69,072 KB
testcase_14 AC 614 ms
62,524 KB
testcase_15 AC 666 ms
62,464 KB
testcase_16 AC 374 ms
60,680 KB
testcase_17 AC 955 ms
69,412 KB
testcase_18 AC 944 ms
70,556 KB
testcase_19 AC 652 ms
62,844 KB
testcase_20 AC 949 ms
69,168 KB
testcase_21 AC 550 ms
62,408 KB
testcase_22 AC 496 ms
60,480 KB
testcase_23 AC 124 ms
55,716 KB
testcase_24 AC 127 ms
56,184 KB
testcase_25 AC 1,046 ms
70,984 KB
testcase_26 AC 1,097 ms
71,456 KB
testcase_27 AC 1,081 ms
71,072 KB
testcase_28 AC 1,041 ms
70,780 KB
testcase_29 AC 1,067 ms
71,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		MultiTreeSet<Long> set = new MultiTreeSet<>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextLong());
		}
		sc.close();

		for (int i = 0; i < n - 1; i++) {
			if (i % 2 == 0) {
				long a = set.pollFirst();
				long b = set.pollFirst();
				set.add(a * b);
			} else {
				long a = set.pollLast();
				long b = set.pollLast();
				set.add((b + a - 1) / a);
			}
		}
		System.out.println(set.pollFirst());
	}

	static class MultiTreeSet<T> {
		TreeMap<T, Integer> map = new TreeMap<>();
		int size = 0;

		void add(T e) {
			map.put(e, map.getOrDefault(e, 0) + 1);
			size++;
		}

		void remove(T e) {
			if (e != null && map.containsKey(e)) {
				int val = map.get(e);
				if (val == 1) {
					map.remove(e);
				} else {
					map.put(e, val - 1);
				}
				size--;
			}
		}

		int sizeAll() {
			return size;
		}

		int sizeUnq() {
			return map.size();
		}

		boolean contains(T e) {
			return map.containsKey(e);
		}

		boolean isEmpty() {
			return size == 0;
		}

		T lower(T e) {
			return map.lowerKey(e);
		}

		T floor(T e) {
			return map.floorKey(e);
		}

		T higher(T e) {
			return map.higherKey(e);
		}

		T ceiling(T e) {
			return map.ceilingKey(e);
		}

		T first() {
			return map.firstKey();
		}

		T last() {
			return map.lastKey();
		}

		T pollFirst() {
			T e = map.firstKey();
			remove(e);
			return e;
		}

		T pollLast() {
			T e = map.lastKey();
			remove(e);
			return e;
		}

		@SuppressWarnings("unchecked")
		T[] toArrayUnq() {
			Object[] arr = map.keySet().toArray();
			return (T[]) arr;
		}

		@SuppressWarnings("unchecked")
		T[] toArrayAll() {
			Object[] arr = new Object[size];
			int idx = 0;
			for (T e : map.keySet()) {
				int num = map.get(e);
				for (int i = 0; i < num; i++) {
					arr[idx] = e;
					idx++;
				}
			}
			return (T[]) arr;
		}
	}
}
0