結果
問題 | No.698 ペアでチームを作ろう |
ユーザー | htensai |
提出日時 | 2020-01-29 09:32:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 133 ms / 1,000 ms |
コード長 | 1,349 bytes |
コンパイル時間 | 1,970 ms |
コンパイル使用メモリ | 74,056 KB |
実行使用メモリ | 52,968 KB |
最終ジャッジ日時 | 2023-10-14 00:18:52 |
合計ジャッジ時間 | 3,582 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,300 KB |
testcase_01 | AC | 43 ms
49,484 KB |
testcase_02 | AC | 44 ms
49,320 KB |
testcase_03 | AC | 43 ms
49,412 KB |
testcase_04 | AC | 43 ms
49,396 KB |
testcase_05 | AC | 133 ms
52,968 KB |
testcase_06 | AC | 47 ms
49,888 KB |
testcase_07 | AC | 45 ms
49,368 KB |
testcase_08 | AC | 44 ms
49,352 KB |
testcase_09 | AC | 45 ms
49,420 KB |
testcase_10 | AC | 46 ms
49,392 KB |
testcase_11 | AC | 45 ms
47,548 KB |
testcase_12 | AC | 45 ms
49,268 KB |
testcase_13 | AC | 44 ms
49,552 KB |
testcase_14 | AC | 45 ms
49,268 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static int n; static int[][] dp; static int[] scores; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); String[] line = br.readLine().split(" ", n); scores = new int[n]; for (int i = 0; i < n; i++) { scores[i] = Integer.parseInt(line[i]); } dp = new int[n / 2 + 1][(int)(Math.pow(2, n))]; System.out.println(dfw(n / 2, (int)(Math.pow(2, n)) - 1)); } static int dfw(int idx, int key) { if (idx == 0) { return 0; } if (dp[idx][key] != 0) { return dp[idx][key]; } int max = 0; for (int i = 0; i < n - 1; i++) { int x = (int)(Math.pow(2, i)); if ((key & x) == 0) { continue; } for (int j = i + 1; j < n; j++) { int y = (int)(Math.pow(2, j)); if ((key & y) == 0) { continue; } max = Math.max(max, dfw(idx - 1, key ^ (x | y)) + (scores[i] ^ scores[j])); } break; } dp[idx][key] = max; return max; } }