結果

問題 No.519 アイドルユニット
ユーザー tentententen
提出日時 2021-05-17 14:50:56
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,716 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 79,596 KB
実行使用メモリ 256,192 KB
最終ジャッジ日時 2024-04-16 03:30:05
合計ジャッジ時間 7,312 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int half = n / 2;
        ArrayList<HashMap<Integer, Integer>> list = new ArrayList<>();
        for (int i = 0; i < half; i++) {
            list.add(new HashMap<>());
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int x = sc.nextInt();
                if (i < j) {
                    list.get(0).put((1 << i) + (1 << j), x);
                }
            }
        }
        for (int i = 0; i < half - 1; i++) {
            for (int x : list.get(i).keySet())  {
                for (int y : list.get(0).keySet()) {
                    if ((x | y) != (x ^ y)) {
                        continue;
                    }
                    list.get(i + 1).put(x | y, Math.max(list.get(i + 1).getOrDefault(x | y, 0), list.get(i).get(x) + list.get(0).get(y)));
                }
            }
        }
        System.out.println(list.get(half - 1).get((1 << n) - 1));
    }
    
}

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