結果

問題 No.698 ペアでチームを作ろう
ユーザー buno15buno15
提出日時 2021-11-06 01:30:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 92 ms / 1,000 ms
コード長 3,749 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 79,984 KB
実行使用メモリ 38,424 KB
最終ジャッジ日時 2024-04-24 10:51:24
合計ジャッジ時間 4,630 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
36,944 KB
testcase_01 AC 55 ms
37,068 KB
testcase_02 AC 55 ms
36,840 KB
testcase_03 AC 53 ms
37,032 KB
testcase_04 AC 63 ms
37,240 KB
testcase_05 AC 76 ms
38,224 KB
testcase_06 AC 92 ms
38,272 KB
testcase_07 AC 80 ms
38,352 KB
testcase_08 AC 79 ms
38,352 KB
testcase_09 AC 83 ms
38,400 KB
testcase_10 AC 91 ms
38,224 KB
testcase_11 AC 75 ms
38,268 KB
testcase_12 AC 91 ms
38,088 KB
testcase_13 AC 79 ms
38,424 KB
testcase_14 AC 81 ms
38,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

	static final int INF = 1000000000;
	static final long MOD = 1000000007;
	static final double EPS = 1e-10;

	public static void main(String args[]) throws IOException {
		IO io = new IO();

		int n = io.getInt();

		int a[] = io.getIntArrPrim();

		long dp[] = new long[1 << 14];
		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;

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

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

class IO {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public IO() {

	}

	public void println(String str) {
		System.out.println(str);
	}

	public void printArr(Object o[]) {
		for (int i = 0; i < o.length; i++) {
			System.out.print(o + " ");
		}
		System.out.println();
	}

	public int getInt() throws IOException {
		return Integer.parseInt(br.readLine());
	}

	public long getLong() throws IOException {
		return Long.parseLong(br.readLine());
	}

	public double getDouble() throws IOException {
		return Double.parseDouble(br.readLine());
	}

	public String getLine() throws IOException {
		return br.readLine();
	}

	public int[] getIntArrPrim() throws IOException {
		String str[] = br.readLine().split(" ");
		int a[] = new int[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		return a;
	}

	public Integer[] getIntArr() throws IOException {
		String str[] = br.readLine().split(" ");
		Integer a[] = new Integer[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		return a;
	}

	public Long[] getLongArr() throws IOException {
		String str[] = br.readLine().split(" ");
		Long a[] = new Long[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		return a;
	}

	public long[] getLongArrPrim() throws IOException {
		String str[] = br.readLine().split(" ");
		long a[] = new long[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		return a;
	}

	public String[] getStrArr(String split) throws IOException {
		return br.readLine().split(split);
	}

	public char[] getCharArr() throws IOException {
		return br.readLine().toCharArray();
	}

	public int[][] getIntMap(int w, int h, String split) throws IOException {
		int a[][] = new int[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = Integer.parseInt(str[j]);
			}
		}

		return a;
	}

	public long[][] getLongMap(int w, int h, String split) throws IOException {
		long a[][] = new long[h][w];

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

		return a;
	}

	public double[][] getDoubleMap(int w, int h, String split) throws IOException {
		double a[][] = new double[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = Double.parseDouble(str[j]);
			}
		}

		return a;
	}

	public char[][] getCharMap(int w, int h, String split) throws IOException {
		char a[][] = new char[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = str[j].charAt(0);
			}
		}

		return a;
	}
}
0