結果

問題 No.771 しおり
ユーザー GrenacheGrenache
提出日時 2019-05-07 19:57:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 427 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 3,693 ms
コンパイル使用メモリ 75,256 KB
実行使用メモリ 93,628 KB
最終ジャッジ日時 2023-09-29 12:54:29
合計ジャッジ時間 12,674 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
93,628 KB
testcase_01 AC 146 ms
60,720 KB
testcase_02 AC 97 ms
56,112 KB
testcase_03 AC 95 ms
56,216 KB
testcase_04 AC 96 ms
55,436 KB
testcase_05 AC 97 ms
55,732 KB
testcase_06 AC 97 ms
54,380 KB
testcase_07 AC 97 ms
55,824 KB
testcase_08 AC 106 ms
55,708 KB
testcase_09 AC 101 ms
55,476 KB
testcase_10 AC 108 ms
55,804 KB
testcase_11 AC 100 ms
55,684 KB
testcase_12 AC 103 ms
55,900 KB
testcase_13 AC 97 ms
55,988 KB
testcase_14 AC 104 ms
56,052 KB
testcase_15 AC 99 ms
55,736 KB
testcase_16 AC 97 ms
55,912 KB
testcase_17 AC 103 ms
55,928 KB
testcase_18 AC 99 ms
56,004 KB
testcase_19 AC 97 ms
55,916 KB
testcase_20 AC 98 ms
55,780 KB
testcase_21 AC 100 ms
56,132 KB
testcase_22 AC 99 ms
56,168 KB
testcase_23 AC 100 ms
55,484 KB
testcase_24 AC 96 ms
55,776 KB
testcase_25 AC 258 ms
72,376 KB
testcase_26 AC 118 ms
55,652 KB
testcase_27 AC 149 ms
60,420 KB
testcase_28 AC 180 ms
64,576 KB
testcase_29 AC 147 ms
60,048 KB
testcase_30 AC 426 ms
93,512 KB
testcase_31 AC 425 ms
93,520 KB
testcase_32 AC 124 ms
55,964 KB
testcase_33 AC 427 ms
93,168 KB
testcase_34 AC 414 ms
93,488 KB
testcase_35 AC 134 ms
56,068 KB
testcase_36 AC 113 ms
55,680 KB
testcase_37 AC 123 ms
55,700 KB
testcase_38 AC 127 ms
56,240 KB
testcase_39 AC 107 ms
55,808 KB
testcase_40 AC 247 ms
72,664 KB
testcase_41 AC 422 ms
93,376 KB
testcase_42 AC 426 ms
93,316 KB
testcase_43 AC 146 ms
60,120 KB
testcase_44 AC 423 ms
93,440 KB
testcase_45 AC 418 ms
93,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder771 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final long INF = Long.MAX_VALUE;

		int n = sc.nextInt();

		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		int m = 0x1 << n;
		long[][] dp = new long[n][m];
		for (int i = 0; i < n; i++) {
			Arrays.fill(dp[i], INF);
			dp[i][0x1 << i] = 0;
		}
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if ((i & 0x1 << j) == 0) {
					continue;
				}

				int d1 = b[j] - a[j];
				for (int k = 0; k < n; k++) {
					if ((i & 0x1 << k) != 0) {
						continue;
					}

					int d2 = a[k];
					dp[k][i | 0x1 << k] = Math.min(dp[k][i | 0x1 << k], Math.max(d1 + d2, dp[j][i]));
				}
			}
		}
		
		long min = INF;
		for (int i = 0; i < n; i++) {
//			pr.println(Arrays.toString(dp[i]));
			min = Math.min(min, dp[i][m - 1]);
		}
		
		pr.println(min);
	}

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

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