結果

問題 No.771 しおり
ユーザー tentententen
提出日時 2022-10-20 15:14:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,091 ms / 2,000 ms
コード長 2,101 bytes
コンパイル時間 4,578 ms
コンパイル使用メモリ 74,392 KB
実行使用メモリ 76,848 KB
最終ジャッジ日時 2023-09-29 13:12:09
合計ジャッジ時間 18,176 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,091 ms
76,404 KB
testcase_01 AC 139 ms
54,276 KB
testcase_02 AC 41 ms
49,256 KB
testcase_03 AC 42 ms
49,316 KB
testcase_04 AC 43 ms
49,360 KB
testcase_05 AC 45 ms
49,432 KB
testcase_06 AC 43 ms
49,316 KB
testcase_07 AC 44 ms
49,340 KB
testcase_08 AC 47 ms
49,400 KB
testcase_09 AC 43 ms
49,592 KB
testcase_10 AC 44 ms
49,460 KB
testcase_11 AC 43 ms
49,356 KB
testcase_12 AC 44 ms
49,580 KB
testcase_13 AC 45 ms
49,584 KB
testcase_14 AC 59 ms
51,692 KB
testcase_15 AC 43 ms
49,296 KB
testcase_16 AC 45 ms
49,268 KB
testcase_17 AC 48 ms
49,380 KB
testcase_18 AC 43 ms
49,304 KB
testcase_19 AC 43 ms
49,656 KB
testcase_20 AC 44 ms
49,460 KB
testcase_21 AC 44 ms
49,492 KB
testcase_22 AC 44 ms
49,396 KB
testcase_23 AC 44 ms
49,748 KB
testcase_24 AC 48 ms
49,324 KB
testcase_25 AC 513 ms
64,760 KB
testcase_26 AC 74 ms
51,936 KB
testcase_27 AC 142 ms
53,976 KB
testcase_28 AC 248 ms
56,712 KB
testcase_29 AC 143 ms
54,144 KB
testcase_30 AC 1,090 ms
76,332 KB
testcase_31 AC 1,087 ms
76,368 KB
testcase_32 AC 81 ms
52,148 KB
testcase_33 AC 1,088 ms
76,400 KB
testcase_34 AC 1,083 ms
76,304 KB
testcase_35 AC 81 ms
51,960 KB
testcase_36 AC 72 ms
51,440 KB
testcase_37 AC 60 ms
51,404 KB
testcase_38 AC 81 ms
51,884 KB
testcase_39 AC 59 ms
49,312 KB
testcase_40 AC 510 ms
64,764 KB
testcase_41 AC 1,074 ms
76,508 KB
testcase_42 AC 1,087 ms
76,848 KB
testcase_43 AC 144 ms
54,428 KB
testcase_44 AC 1,088 ms
76,364 KB
testcase_45 AC 1,084 ms
76,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] marks;
    static int[] books;
    static int[][] dp;
    static int n;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        n = sc.nextInt();
        marks = new int[n];
        books = new int[n];
        for (int i = 0; i < n; i++) {
            marks[i] = sc.nextInt();
            books[i] = sc.nextInt();
        }
        dp = new int[1 << n][n];
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            ans = Math.min(ans, dfw((1 << n) - 1, i));
        }
        System.out.println(ans);
    }
    
    static int dfw(int mask, int idx) {
        if (getPop(mask) == 1) {
            return 0;
        }
        if (dp[mask][idx] == 0) {
            dp[mask][idx] = Integer.MAX_VALUE / 2;
            for (int i = 0; i < n; i++) {
                if (i == idx || (mask & (1 << i)) == 0) {
                    continue;
                }
                dp[mask][idx] = Math.min(dp[mask][idx], Math.max(dfw(mask ^ (1 << idx), i), books[i] - marks[i] + marks[idx]));
            }
        }
        return dp[mask][idx];
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return pop;
    }
    
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0