結果
問題 |
No.698 ペアでチームを作ろう
|
ユーザー |
![]() |
提出日時 | 2020-03-24 20:55:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 75 ms / 1,000 ms |
コード長 | 1,394 bytes |
コンパイル時間 | 400 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 76,508 KB |
最終ジャッジ日時 | 2024-12-31 19:02:49 |
合計ジャッジ時間 | 1,932 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#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 #誰がペアを作るか for i in range(N): cur = 0 if (s>>i) == 0: #片方の戦闘力 cur = a[i] new_s = s|1<<i dp[new_s] = dp[s] #ペアを作る相手とその時の戦闘力 for j in range(N): if (new_s>>j) & 1 == 0: dp[new_s|1<<j] = max(dp[new_s|1<<j], dp[new_s]+(cur^a[j])) print(dp[-1]) if __name__ == '__main__': main()