結果
問題 | No.698 ペアでチームを作ろう |
ユーザー | tenten |
提出日時 | 2020-09-03 19:22:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 186 ms / 1,000 ms |
コード長 | 1,226 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 78,388 KB |
実行使用メモリ | 54,904 KB |
最終ジャッジ日時 | 2024-05-03 02:07:31 |
合計ジャッジ時間 | 5,228 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 117 ms
53,936 KB |
testcase_01 | AC | 119 ms
54,188 KB |
testcase_02 | AC | 122 ms
53,436 KB |
testcase_03 | AC | 102 ms
53,100 KB |
testcase_04 | AC | 151 ms
54,304 KB |
testcase_05 | AC | 155 ms
54,520 KB |
testcase_06 | AC | 166 ms
54,824 KB |
testcase_07 | AC | 153 ms
54,844 KB |
testcase_08 | AC | 186 ms
54,904 KB |
testcase_09 | AC | 156 ms
54,740 KB |
testcase_10 | AC | 175 ms
54,660 KB |
testcase_11 | AC | 163 ms
54,584 KB |
testcase_12 | AC | 175 ms
54,688 KB |
testcase_13 | AC | 173 ms
54,624 KB |
testcase_14 | AC | 160 ms
54,500 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int[] dp = new int[1 << n]; HashSet<Integer> pair = new HashSet<>(); for (int i = 1; i < (1 << n); i++) { int count = getPopcount(i); if (count == 2) { int base = 0; int value = i; for (int j = 0; j < n; j++) { if (value % 2 == 1) { base ^= arr[j]; } value /= 2; } dp[i] = base; pair.add(i); } else if (count % 2 == 0) { int max = 0; for (int x : pair) { if ((x & i) != x) { continue; } max = Math.max(max, dp[x] + dp[i ^ x]); } dp[i] = max; } } System.out.println(dp[(1 << n) - 1]); } static int getPopcount(int x) { int count = 0; while (x > 0) { count += x % 2; x /= 2; } return count; } }