結果

問題 No.698 ペアでチームを作ろう
ユーザー UekiUeki
提出日時 2019-05-15 15:41:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 462 ms / 1,000 ms
コード長 663 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 8,780 KB
最終ジャッジ日時 2023-10-12 02:27:07
合計ジャッジ時間 5,947 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,956 KB
testcase_01 AC 17 ms
7,812 KB
testcase_02 AC 31 ms
7,956 KB
testcase_03 AC 16 ms
7,776 KB
testcase_04 AC 100 ms
8,196 KB
testcase_05 AC 437 ms
8,180 KB
testcase_06 AC 434 ms
8,228 KB
testcase_07 AC 460 ms
8,644 KB
testcase_08 AC 462 ms
8,768 KB
testcase_09 AC 460 ms
8,608 KB
testcase_10 AC 453 ms
8,708 KB
testcase_11 AC 446 ms
8,628 KB
testcase_12 AC 457 ms
8,628 KB
testcase_13 AC 453 ms
8,608 KB
testcase_14 AC 449 ms
8,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

dp = [0]*(1 << N)


# maskはすでにペアを作っている人の集合
for mask in range(1 << N):
    for a in range(N):
        if mask >> a & 1 == 1:
            continue
        for b in range(a+1, N):
            # ここで、aとbをペアにする
            if mask >> b & 1 == 0:  # a,b両方ともまだ使われていないなら
                new_state = mask | 1 << a | 1 << b
                dp[new_state] = max(dp[new_state], dp[mask]+(A[a] ^ A[b]))
print(dp[-1])
0