結果

問題 No.519 アイドルユニット
ユーザー tentententen
提出日時 2021-05-17 15:13:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 765 ms / 1,000 ms
コード長 1,984 bytes
コンパイル時間 2,530 ms
コンパイル使用メモリ 79,064 KB
実行使用メモリ 66,568 KB
最終ジャッジ日時 2024-04-16 03:45:55
合計ジャッジ時間 12,384 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 729 ms
62,748 KB
testcase_01 AC 755 ms
63,788 KB
testcase_02 AC 325 ms
53,808 KB
testcase_03 AC 126 ms
42,392 KB
testcase_04 AC 57 ms
37,020 KB
testcase_05 AC 57 ms
36,740 KB
testcase_06 AC 56 ms
36,784 KB
testcase_07 AC 58 ms
37,212 KB
testcase_08 AC 61 ms
37,268 KB
testcase_09 AC 85 ms
38,156 KB
testcase_10 AC 105 ms
39,688 KB
testcase_11 AC 123 ms
41,996 KB
testcase_12 AC 56 ms
36,616 KB
testcase_13 AC 126 ms
41,868 KB
testcase_14 AC 127 ms
42,060 KB
testcase_15 AC 125 ms
41,868 KB
testcase_16 AC 121 ms
41,972 KB
testcase_17 AC 126 ms
41,996 KB
testcase_18 AC 124 ms
42,232 KB
testcase_19 AC 124 ms
41,628 KB
testcase_20 AC 126 ms
42,272 KB
testcase_21 AC 127 ms
42,084 KB
testcase_22 AC 127 ms
42,008 KB
testcase_23 AC 127 ms
42,144 KB
testcase_24 AC 179 ms
46,480 KB
testcase_25 AC 174 ms
47,020 KB
testcase_26 AC 182 ms
46,868 KB
testcase_27 AC 185 ms
47,400 KB
testcase_28 AC 182 ms
47,452 KB
testcase_29 AC 689 ms
62,676 KB
testcase_30 AC 706 ms
63,016 KB
testcase_31 AC 765 ms
65,964 KB
testcase_32 AC 713 ms
66,568 KB
testcase_33 AC 55 ms
37,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static ArrayList<HashSet<Integer>> base = new ArrayList<>();
    static HashMap<Integer, Integer> dp = new HashMap<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            base.add(new HashSet<>());
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int x = sc.nextInt();
                if (i < j) {
                    dp.put((1 << i) + (1 << j), x);
                    base.get(i).add((1 << i) + (1 << j));
                }
            }
        }
        System.out.println(dfw((1 << n) - 1));
    }
    
    static int dfw(int mask) {
        if (!dp.containsKey(mask)) {
            int max = 0;
            int idx = getIdx(mask);
            for (int x : base.get(idx)) {
                if ((mask & x) != x) {
                    continue;
                }
                max = Math.max(max, dfw(x) + dfw(mask ^ x));
            }
            dp.put(mask, max);
        }
        return dp.get(mask);
    }
    
    static int getIdx(int mask) {
        int idx = 0;
        while (mask > 0) {
            if (mask % 2 == 1) {
                break;
            }
            idx++;
            mask >>= 1;
        }
        return idx;
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0