結果

問題 No.698 ペアでチームを作ろう
ユーザー GrenacheGrenache
提出日時 2018-09-22 14:56:19
言語 Java19
(openjdk 21)
結果
AC  
実行時間 321 ms / 1,000 ms
コード長 1,865 bytes
コンパイル時間 3,845 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 62,892 KB
最終ジャッジ日時 2023-09-25 11:03:13
合計ジャッジ時間 8,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,328 KB
testcase_01 AC 122 ms
56,080 KB
testcase_02 AC 161 ms
53,312 KB
testcase_03 AC 121 ms
55,548 KB
testcase_04 AC 214 ms
58,472 KB
testcase_05 AC 300 ms
62,620 KB
testcase_06 AC 307 ms
62,260 KB
testcase_07 AC 319 ms
62,544 KB
testcase_08 AC 306 ms
60,920 KB
testcase_09 AC 305 ms
62,504 KB
testcase_10 AC 307 ms
62,420 KB
testcase_11 AC 306 ms
62,492 KB
testcase_12 AC 312 ms
62,708 KB
testcase_13 AC 321 ms
62,688 KB
testcase_14 AC 320 ms
62,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.Map.*;


public class Main_yukicoder698 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		Map<Integer, Long> hm = new HashMap<>();

		// nn個のビットのうち、ii個のビットが立っているmaskのパターンの生成
		int nn = n;
		int ii = 2;

		int mask = (0x1 << ii) - 1;
		while (mask < 0x1 << nn) {
			// maskに対する処理

			long tmp = 0;
			for (int j = 0; j < n; j++) {
				if ((mask & 0x1 << j) != 0) {
					tmp ^= a[j];
				}
			}
			
			hm.put(mask, tmp);

			// 次のmaskの計算
			int xx = mask & -mask;
			int yy = mask + xx;
			mask = ((mask & ~yy) / xx >> 1) | yy;
		}

		
		Map<Integer, Long> hm2 = new HashMap<>(hm);
		for (int i = 4; i <= n; i += 2) {
			Map<Integer, Long> hmtmp = new HashMap<>();
			for (Entry<Integer, Long> e : hm.entrySet()) {
				int key = e.getKey();
				long value = e.getValue();
				for (Entry<Integer, Long> ee : hm2.entrySet()) {
					int nkey = key | ee.getKey();
					if (Integer.bitCount(nkey) != i) {
						continue;
					}
					
					if (!hmtmp.containsKey(nkey)) {
						hmtmp.put(nkey, 0L);
					}
					hmtmp.put(nkey, Math.max(hmtmp.get(nkey), value + hm2.get(ee.getKey())));
				}
			}
			
			hm2 = hmtmp;
		}
		
		pr.println(hm2.get((0x1 << n) - 1));
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0