結果

問題 No.699 ペアでチームを作ろう2
ユーザー tentententen
提出日時 2021-12-01 20:27:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 83 ms / 1,000 ms
コード長 1,747 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 74,712 KB
実行使用メモリ 52,132 KB
最終ジャッジ日時 2023-09-18 05:11:01
合計ジャッジ時間 3,823 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,384 KB
testcase_01 AC 43 ms
47,276 KB
testcase_02 AC 44 ms
49,204 KB
testcase_03 AC 42 ms
49,420 KB
testcase_04 AC 59 ms
50,964 KB
testcase_05 AC 73 ms
51,580 KB
testcase_06 AC 72 ms
52,132 KB
testcase_07 AC 83 ms
52,000 KB
testcase_08 AC 81 ms
51,620 KB
testcase_09 AC 75 ms
52,080 KB
testcase_10 AC 74 ms
51,780 KB
testcase_11 AC 79 ms
51,692 KB
testcase_12 AC 77 ms
51,620 KB
testcase_13 AC 78 ms
51,796 KB
testcase_14 AC 72 ms
51,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int n;
    static int[] values;
    static int max = 0;
    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();
        }
        check(0, new boolean[n], 0);
        System.out.println(max);
    }
    
    static void check(int idx, boolean[] used, int v) {
        if (idx >= n) {
            max = Math.max(max, v);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (used[i]) {
                continue;
            }
            used[i] = true;
            for (int j = i + 1; j < n; j++) {
                if (used[j]) {
                    continue;
                }
                used[j] = true;
                check(idx + 2, used, v ^ (values[i] + values[j]));
                used[j] = false;
            }
            used[i] = false;
            break;
        }
    }
}
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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0