結果

問題 No.519 アイドルユニット
ユーザー tenten
提出日時 2021-05-17 14:50:56
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,716 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 78,736 KB
実行使用メモリ 272,992 KB
最終ジャッジ日時 2024-10-06 14:20:57
合計ジャッジ時間 7,116 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 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