結果

問題 No.771 しおり
ユーザー htensaihtensai
提出日時 2020-01-29 13:44:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 2,558 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 73,656 KB
最終ジャッジ日時 2023-09-29 13:01:22
合計ジャッジ時間 12,135 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 422 ms
72,876 KB
testcase_01 AC 86 ms
53,720 KB
testcase_02 AC 43 ms
49,308 KB
testcase_03 AC 43 ms
49,356 KB
testcase_04 AC 43 ms
49,568 KB
testcase_05 AC 57 ms
49,252 KB
testcase_06 AC 43 ms
49,372 KB
testcase_07 AC 43 ms
49,164 KB
testcase_08 AC 48 ms
49,256 KB
testcase_09 AC 43 ms
49,360 KB
testcase_10 AC 43 ms
49,360 KB
testcase_11 AC 43 ms
49,252 KB
testcase_12 AC 44 ms
49,248 KB
testcase_13 AC 43 ms
49,472 KB
testcase_14 AC 49 ms
49,372 KB
testcase_15 AC 42 ms
49,416 KB
testcase_16 AC 44 ms
49,672 KB
testcase_17 AC 44 ms
49,272 KB
testcase_18 AC 42 ms
49,736 KB
testcase_19 AC 44 ms
49,216 KB
testcase_20 AC 44 ms
49,520 KB
testcase_21 AC 43 ms
49,700 KB
testcase_22 AC 44 ms
49,260 KB
testcase_23 AC 44 ms
49,224 KB
testcase_24 AC 44 ms
49,252 KB
testcase_25 AC 254 ms
59,892 KB
testcase_26 AC 57 ms
51,160 KB
testcase_27 AC 84 ms
53,528 KB
testcase_28 AC 120 ms
55,912 KB
testcase_29 AC 83 ms
53,616 KB
testcase_30 AC 418 ms
72,976 KB
testcase_31 AC 420 ms
72,972 KB
testcase_32 AC 60 ms
51,528 KB
testcase_33 AC 405 ms
73,008 KB
testcase_34 AC 422 ms
72,944 KB
testcase_35 AC 61 ms
51,572 KB
testcase_36 AC 57 ms
51,352 KB
testcase_37 AC 56 ms
51,320 KB
testcase_38 AC 60 ms
51,612 KB
testcase_39 AC 55 ms
49,552 KB
testcase_40 AC 206 ms
59,904 KB
testcase_41 AC 417 ms
72,908 KB
testcase_42 AC 408 ms
73,020 KB
testcase_43 AC 84 ms
53,652 KB
testcase_44 AC 415 ms
72,896 KB
testcase_45 AC 411 ms
73,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] befores;
    static int[] afters;
    static int[][] dp;
    static int n;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        befores = new int[n];
        afters = new int[n];
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ", 2);
            befores[i] = Integer.parseInt(line[0]);
            afters[i] = Integer.parseInt(line[1]) - befores[i];
        }
        dp = new int[n + 1][1 << n];
        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 key) {
        if (key == 1 << idx) {
            return 0;
        }
        if (dp[idx][key] != 0) {
            return dp[idx][key];
        }
        int min = Integer.MAX_VALUE;
        int next = key ^ (1 << idx);
        for (int i = 0; i < n; i++) {
            int x = 1 << i;
            if ((next & x) == 0) {
                continue;
            }
            min = Math.min(min, Math.max(dfw(i, next), afters[i] + befores[idx]));
        }
        dp[idx][key] = min;
        return min;
    }
}
0