結果

問題 No.699 ペアでチームを作ろう2
ユーザー tentententen
提出日時 2020-09-03 19:45:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 156 ms / 1,000 ms
コード長 1,081 bytes
コンパイル時間 4,866 ms
コンパイル使用メモリ 83,648 KB
実行使用メモリ 41,668 KB
最終ジャッジ日時 2024-11-23 23:17:09
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[] arr;
    static int max = 0;
	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();
    	}
    	boolean[] used = new boolean[n];
    	calc(0, 0, used);
    	System.out.println(max);
	}
	
	static void calc(int count, int value, boolean[] used) {
	    if (count == n) {
	        max = Math.max(max, value);
	    }
	    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]) {
	                used[j] = true;
	                calc(count + 2, value ^ (arr[i] + arr[j]), used);
	                used[j] = false;
	            }
	        }
	        used[i] = false;
	        break;
	    }
	}
	
	static int getPopcount(int x) {
	    int count = 0;
	    while (x > 0) {
	        count += x % 2;
	        x /= 2;
	    }
	    return count;
	}
}
0