結果

問題 No.698 ペアでチームを作ろう
ユーザー buno15buno15
提出日時 2020-10-22 00:42:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 76 ms / 1,000 ms
コード長 860 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 73,908 KB
実行使用メモリ 52,216 KB
最終ジャッジ日時 2023-09-28 14:30:56
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,152 KB
testcase_01 AC 43 ms
49,288 KB
testcase_02 AC 45 ms
49,152 KB
testcase_03 AC 43 ms
49,140 KB
testcase_04 AC 53 ms
49,936 KB
testcase_05 AC 62 ms
51,316 KB
testcase_06 AC 67 ms
51,632 KB
testcase_07 AC 76 ms
49,668 KB
testcase_08 AC 63 ms
51,284 KB
testcase_09 AC 75 ms
51,936 KB
testcase_10 AC 64 ms
51,432 KB
testcase_11 AC 70 ms
51,852 KB
testcase_12 AC 76 ms
52,216 KB
testcase_13 AC 63 ms
51,188 KB
testcase_14 AC 71 ms
51,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		long a[] = new long[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		long dp[] = new long[1 << n];

		dp[0] = 0;

		for (int bit = 0; bit < (1 << n); bit++) {
			for (int i = 0; i < n; i++) {
				if (((bit & (1 << i)) == 0))
					continue;

				for (int j = i + 1; j < n; j++) {
					if (((bit & (1 << j)) == 0))
						continue;

					long t = dp[bit - (1 << i) - (1 << j)] + (a[i] ^ a[j]);
					dp[bit] = Math.max(dp[bit], t);
				}
			}
		}

		System.out.println(dp[(1 << n) - 1]);
	}
}
0