結果

問題 No.699 ペアでチームを作ろう2
ユーザー tentententen
提出日時 2020-09-03 19:45:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 1,000 ms
コード長 1,081 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 77,248 KB
実行使用メモリ 54,456 KB
最終ジャッジ日時 2024-05-03 02:50:25
合計ジャッジ時間 5,110 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
52,804 KB
testcase_01 AC 114 ms
53,896 KB
testcase_02 AC 138 ms
54,100 KB
testcase_03 AC 116 ms
54,172 KB
testcase_04 AC 144 ms
54,348 KB
testcase_05 AC 141 ms
54,392 KB
testcase_06 AC 142 ms
54,376 KB
testcase_07 AC 142 ms
53,972 KB
testcase_08 AC 146 ms
54,292 KB
testcase_09 AC 137 ms
53,908 KB
testcase_10 AC 129 ms
53,904 KB
testcase_11 AC 144 ms
54,088 KB
testcase_12 AC 145 ms
54,284 KB
testcase_13 AC 147 ms
54,456 KB
testcase_14 AC 139 ms
54,252 KB
権限があれば一括ダウンロードができます

ソースコード

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