結果

問題 No.698 ペアでチームを作ろう
ユーザー efunyoefunyo
提出日時 2020-03-24 20:25:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,377 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 78,104 KB
最終ジャッジ日時 2023-08-30 05:45:44
合計ジャッジ時間 3,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,680 KB
testcase_01 AC 102 ms
71,720 KB
testcase_02 AC 118 ms
77,732 KB
testcase_03 AC 96 ms
71,756 KB
testcase_04 WA -
testcase_05 AC 123 ms
77,616 KB
testcase_06 AC 122 ms
77,732 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 122 ms
77,804 KB
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#https://yukicoder.me/problems/no/698

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    #dp[s]:sは作成済みのペア
    #         dp[s]はその時の戦闘力
    dp = [0]*(1<<N)

    for s in range(1<<N):
        #1が奇数個の場合はスルー
        cnt = 0
        for i in range(N):
            if (s>>i) & 1:
                cnt += 1
        if cnt%2 != 0:
            continue

        cur = 0
        #誰がペアを作るか
        for i in range(N):
            if (s>>i) == 0:
                #片方の戦闘力
                cur = a[i]
                dp[s|1<<i] = dp[s]
                s = s|1<<i
                break
        
        #ペアと作る相手とその時の戦闘力
        for i in range(N):
            if (s>>i) & 1:
                continue
            dp[s|1<<i] = max(dp[s|1<<i], dp[s]+(cur^a[i]))
    print(dp[-1])

if __name__ == '__main__':
    main()
0