結果

問題 No.771 しおり
ユーザー tentententen
提出日時 2021-01-19 11:17:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 712 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 74,676 KB
実行使用メモリ 72,812 KB
最終ジャッジ日時 2023-09-29 13:05:09
合計ジャッジ時間 16,383 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 696 ms
72,148 KB
testcase_01 AC 176 ms
57,864 KB
testcase_02 AC 124 ms
56,180 KB
testcase_03 AC 123 ms
56,184 KB
testcase_04 AC 122 ms
56,084 KB
testcase_05 AC 124 ms
56,324 KB
testcase_06 AC 125 ms
56,040 KB
testcase_07 AC 125 ms
55,904 KB
testcase_08 AC 132 ms
56,020 KB
testcase_09 AC 121 ms
54,120 KB
testcase_10 AC 125 ms
56,064 KB
testcase_11 AC 123 ms
56,060 KB
testcase_12 AC 125 ms
55,792 KB
testcase_13 AC 125 ms
55,996 KB
testcase_14 AC 133 ms
55,524 KB
testcase_15 AC 121 ms
56,024 KB
testcase_16 AC 121 ms
56,368 KB
testcase_17 AC 126 ms
55,988 KB
testcase_18 AC 126 ms
56,156 KB
testcase_19 AC 126 ms
56,496 KB
testcase_20 AC 124 ms
56,312 KB
testcase_21 AC 123 ms
56,428 KB
testcase_22 AC 122 ms
55,824 KB
testcase_23 AC 124 ms
55,524 KB
testcase_24 AC 127 ms
56,032 KB
testcase_25 AC 345 ms
64,576 KB
testcase_26 AC 135 ms
55,832 KB
testcase_27 AC 174 ms
57,908 KB
testcase_28 AC 220 ms
60,252 KB
testcase_29 AC 175 ms
57,996 KB
testcase_30 AC 676 ms
72,352 KB
testcase_31 AC 712 ms
72,376 KB
testcase_32 AC 150 ms
55,884 KB
testcase_33 AC 690 ms
72,728 KB
testcase_34 AC 698 ms
72,812 KB
testcase_35 AC 152 ms
55,532 KB
testcase_36 AC 135 ms
56,088 KB
testcase_37 AC 135 ms
55,696 KB
testcase_38 AC 152 ms
56,132 KB
testcase_39 AC 135 ms
55,948 KB
testcase_40 AC 350 ms
64,224 KB
testcase_41 AC 702 ms
72,504 KB
testcase_42 AC 702 ms
72,372 KB
testcase_43 AC 176 ms
58,164 KB
testcase_44 AC 699 ms
72,536 KB
testcase_45 AC 703 ms
72,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[] positions;
    static int[] sizes;
    static int[][] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		positions = new int[n];
		sizes = new int[n];
		for (int i = 0; i < n; i++) {
		    positions[i] = sc.nextInt();
		    sizes[i] = sc.nextInt();
		}
		dp = new int[n][1 << n];
		for (int[] arr : dp) {
		    Arrays.fill(arr, -1);
		}
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
		    min = Math.min(min, dfw(i, (1 << n) - 1));
		}
		System.out.println(min);
	}
	
	static int dfw(int idx, int mask) {
	    if (dp[idx][mask] < 0) {
	        int next = ((1 << idx) ^ mask);
	        if (next == 0) {
	            dp[idx][mask] = 0;
	            return 0;
	        }
	        int min = Integer.MAX_VALUE;
	        for (int i = 0; i < n; i++) {
	            if (((1 << i) & next) == 0) {
	                continue;
	            }
	            int length = sizes[idx] - positions[idx] + positions[i];
	            min = Math.min(min, Math.max(length,dfw(i, next)));
	        }
	        dp[idx][mask] = min;
	    }
	    return dp[idx][mask];
	}
}
0