結果
問題 |
No.698 ペアでチームを作ろう
|
ユーザー |
|
提出日時 | 2018-09-22 14:56:19 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 268 ms / 1,000 ms |
コード長 | 1,865 bytes |
コンパイル時間 | 3,392 ms |
コンパイル使用メモリ | 80,128 KB |
実行使用メモリ | 60,604 KB |
最終ジャッジ日時 | 2024-07-18 08:56:38 |
合計ジャッジ時間 | 7,052 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
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); } } }