結果

問題 No.771 しおり
ユーザー htensaihtensai
提出日時 2020-01-29 13:38:35
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,454 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 74,260 KB
実行使用メモリ 75,724 KB
最終ジャッジ日時 2023-10-14 05:37:25
合計ジャッジ時間 32,856 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 228 ms
53,828 KB
testcase_02 AC 42 ms
49,256 KB
testcase_03 AC 42 ms
49,296 KB
testcase_04 AC 42 ms
49,408 KB
testcase_05 AC 42 ms
49,600 KB
testcase_06 AC 42 ms
49,372 KB
testcase_07 AC 41 ms
49,208 KB
testcase_08 AC 46 ms
47,428 KB
testcase_09 AC 42 ms
49,328 KB
testcase_10 AC 41 ms
49,288 KB
testcase_11 AC 41 ms
49,228 KB
testcase_12 AC 42 ms
49,684 KB
testcase_13 AC 45 ms
49,232 KB
testcase_14 AC 66 ms
51,304 KB
testcase_15 AC 41 ms
49,360 KB
testcase_16 AC 42 ms
49,684 KB
testcase_17 AC 44 ms
49,228 KB
testcase_18 AC 42 ms
49,572 KB
testcase_19 AC 42 ms
49,380 KB
testcase_20 AC 41 ms
49,208 KB
testcase_21 AC 42 ms
49,696 KB
testcase_22 AC 43 ms
49,536 KB
testcase_23 AC 45 ms
49,332 KB
testcase_24 AC 44 ms
49,540 KB
testcase_25 AC 1,029 ms
59,744 KB
testcase_26 AC 69 ms
51,712 KB
testcase_27 AC 228 ms
53,592 KB
testcase_28 AC 474 ms
56,136 KB
testcase_29 AC 227 ms
53,572 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 87 ms
51,552 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 87 ms
51,744 KB
testcase_36 AC 71 ms
51,300 KB
testcase_37 AC 70 ms
51,168 KB
testcase_38 AC 88 ms
51,756 KB
testcase_39 AC 69 ms
51,252 KB
testcase_40 AC 1,046 ms
59,664 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 AC 229 ms
53,752 KB
testcase_44 TLE -
testcase_45 TLE -
権限があれば一括ダウンロードができます

ソースコード

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][(int)(Math.pow(2, n))];
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            min = Math.min(min, dfw(i, (int)(Math.pow(2, n) - 1)));
        }
        System.out.println(min);
    }
    
    static int dfw(int idx, int key) {
        if (key == (int)(Math.pow(2, idx))) {
            return 0;
        }
        if (dp[idx][key] != 0) {
            return dp[idx][key];
        }
        int min = Integer.MAX_VALUE;
        int next = key ^ (int)(Math.pow(2, idx));
        for (int i = 0; i < n; i++) {
            int x = (int)(Math.pow(2, 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