結果

問題 No.698 ペアでチームを作ろう
ユーザー takeya_okinotakeya_okino
提出日時 2019-07-27 13:24:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 1,000 ms
コード長 731 bytes
コンパイル時間 2,559 ms
コンパイル使用メモリ 73,872 KB
実行使用メモリ 56,048 KB
最終ジャッジ日時 2023-09-15 06:12:43
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,032 KB
testcase_01 AC 125 ms
55,456 KB
testcase_02 AC 129 ms
56,048 KB
testcase_03 AC 126 ms
55,964 KB
testcase_04 AC 137 ms
55,680 KB
testcase_05 AC 141 ms
55,464 KB
testcase_06 AC 142 ms
55,540 KB
testcase_07 AC 143 ms
55,724 KB
testcase_08 AC 143 ms
56,028 KB
testcase_09 AC 145 ms
55,800 KB
testcase_10 AC 144 ms
55,756 KB
testcase_11 AC 146 ms
55,820 KB
testcase_12 AC 142 ms
55,776 KB
testcase_13 AC 144 ms
55,740 KB
testcase_14 AC 144 ms
55,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    int p = (int)Math.pow(2, n);
    int[] dp = new int[p];

    for(int i = 1; i < p; i++) {
      for(int j = 0; j < n; j++) {
        if((i & (1 << j)) != 0) {
          for(int k = j + 1; k < n; k++) {
            if((i & (1 << k)) != 0) {
              int i1 = i - (1 << j) - (1 << k);
              int t = dp[i1];
              t += (a[j] ^ a[k]);
              dp[i] = Math.max(dp[i], t);
            }
          }
        }
      }
    }
    System.out.println(dp[p - 1]);
  }
}
0