結果

問題 No.798 コレクション
ユーザー 37zigen37zigen
提出日時 2018-08-05 20:01:07
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,345 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 76,136 KB
実行使用メモリ 56,308 KB
最終ジャッジ日時 2023-09-11 02:23:49
合計ジャッジ時間 6,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,120 KB
testcase_01 AC 125 ms
55,792 KB
testcase_02 AC 126 ms
55,796 KB
testcase_03 AC 125 ms
56,308 KB
testcase_04 AC 123 ms
55,988 KB
testcase_05 AC 126 ms
56,196 KB
testcase_06 AC 125 ms
55,688 KB
testcase_07 AC 125 ms
55,600 KB
testcase_08 AC 125 ms
55,772 KB
testcase_09 AC 123 ms
55,588 KB
testcase_10 AC 125 ms
55,740 KB
testcase_11 AC 124 ms
55,984 KB
testcase_12 AC 124 ms
55,528 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 125 ms
55,836 KB
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if (!(1 <= N && N <= 17))
			throw new AssertionError();
		long[][] A = new long[N][2];
		for (int i = 0; i < N; ++i) {
			A[i][0] = sc.nextLong();
			A[i][1] = sc.nextLong();
			if (!(1 <= A[i][0] && A[i][0] <= 1e5 && 1 <= A[i][1] && A[i][1] <= 1e5))
				throw new AssertionError();
		}
		Arrays.sort(A, new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return -Long.compare(o1[1], o2[1]);
			}
		});
		long[][] dp = new long[N + 1][N + 1];
		for (int i = 0; i < dp.length; ++i)
			for (int j = 0; j < dp[i].length; ++j)
				dp[i][j] = Long.MAX_VALUE / 3;
		dp[0][0] = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j <= N; ++j) {
				if (j + 1 <= N)
					dp[i + 1][j + 1] = Math.min(dp[i + 1][j + 1], dp[i][j] + A[i][0] + A[i][1] * j);
				dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);
			}
		}
		int sub = 0;
		for (int i = 0, res = N; res > 0; ++i) {
			--res;
			if (i % 2 == 1 && res > 0) {
				--res;
				++sub;
			}
		}
		System.out.println(dp[N][N - sub]);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0