結果

問題 No.699 ペアでチームを作ろう2
ユーザー tentententen
提出日時 2021-11-02 15:45:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 853 ms / 1,000 ms
コード長 2,055 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 78,964 KB
実行使用メモリ 74,452 KB
最終ジャッジ日時 2024-04-20 01:16:53
合計ジャッジ時間 9,829 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,484 KB
testcase_01 AC 51 ms
50,440 KB
testcase_02 AC 66 ms
51,932 KB
testcase_03 AC 51 ms
50,284 KB
testcase_04 AC 128 ms
55,896 KB
testcase_05 AC 181 ms
57,900 KB
testcase_06 AC 193 ms
59,104 KB
testcase_07 AC 583 ms
71,772 KB
testcase_08 AC 652 ms
71,540 KB
testcase_09 AC 781 ms
74,452 KB
testcase_10 AC 853 ms
73,376 KB
testcase_11 AC 644 ms
72,068 KB
testcase_12 AC 830 ms
72,632 KB
testcase_13 AC 842 ms
72,512 KB
testcase_14 AC 704 ms
73,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int n;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        n = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        System.out.println(check1(0, new boolean[n]).last());
    }
    
    static TreeSet<Integer> check1(int idx, boolean[] used) {
        if (idx == n) {
            TreeSet<Integer> ans = new TreeSet<>();
            ans.add(0);
            return ans;
        }
        TreeSet<Integer> ans = null;
        for (int i = 0; i < n; i++) {
            if (!used[i]) {
                used[i] = true;
                ans = check2(idx + 1, used, values[i]);
                used[i] = false;
                break;
            }
        }
        return ans;
    }
    
    static TreeSet<Integer> check2(int idx, boolean[] used, int v) {
        TreeSet<Integer> ans = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            if (used[i]) {
                continue;
            } 
            used[i] = true;
            TreeSet<Integer> tmp = check1(idx + 1, used);
            for (int x : tmp) {
                ans.add((v + values[i]) ^ x);
            }
            used[i] = false;
        }
        return ans;
    }
    
}
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 nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0