結果

問題 No.699 ペアでチームを作ろう2
ユーザー htensaihtensai
提出日時 2020-01-07 12:18:36
言語 Java19
(openjdk 21)
結果
AC  
実行時間 265 ms / 1,000 ms
コード長 1,279 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 73,640 KB
実行使用メモリ 59,480 KB
最終ジャッジ日時 2023-08-14 23:13:57
合計ジャッジ時間 6,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,912 KB
testcase_01 AC 123 ms
56,004 KB
testcase_02 AC 145 ms
56,520 KB
testcase_03 AC 121 ms
56,464 KB
testcase_04 AC 153 ms
58,860 KB
testcase_05 AC 262 ms
58,652 KB
testcase_06 AC 256 ms
59,180 KB
testcase_07 AC 262 ms
59,116 KB
testcase_08 AC 261 ms
59,072 KB
testcase_09 AC 262 ms
59,480 KB
testcase_10 AC 258 ms
58,836 KB
testcase_11 AC 262 ms
59,136 KB
testcase_12 AC 261 ms
58,912 KB
testcase_13 AC 265 ms
59,256 KB
testcase_14 AC 262 ms
58,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[] arr;
    static int max = Integer.MIN_VALUE;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        arr = new int[n];
        for (int i = 0; i < n; i++ ){
            arr[i] = sc.nextInt();
        }
        search(1, new int[n]);
        System.out.println(max);
    }
    
    static void search(int count, int[] used) {
        if (count > n / 2) {
            int[] base = new int[n / 2 + 1];
            for (int i = 0; i < n; i++) {
                base[used[i]] += arr[i];
            }
            int ans = 0;
            for (int i = 1; i < base.length; i++) {
                ans ^= base[i];
            }
            max = Math.max(ans, max);
            return;
        }
        for (int i = count - 1; i < count * 2 - 1; i++) {
            if (used[i] != 0) {
                continue;
            }
            used[i] = count;
            for (int j = i + 1; j < n; j++) {
                if (used[j] != 0) {
                    continue;
                }
                used[j] = count;
                search(count + 1, used);
                used[j] = 0;
            }
            used[i] = 0;
        }
    }
}
0