結果

問題 No.698 ペアでチームを作ろう
ユーザー ikdikd
提出日時 2018-07-15 19:27:10
言語 Nim
(2.0.2)
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 550 bytes
コンパイル時間 3,062 ms
コンパイル使用メモリ 68,420 KB
実行使用メモリ 5,068 KB
最終ジャッジ日時 2023-09-13 18:33:06
合計ジャッジ時間 3,917 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
5,068 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 39) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 39) Warning: imported and not used: 'future' [UnusedImport]

ソースコード

diff #

import strutils, sequtils, algorithm, future

var
  n=stdin.readLine.parseInt
  a=stdin.readLine.split.map(parseInt)
  memo=newSeq[int](1 shl n)

fill(memo, -1) # algorithm
proc f(bit: int): int=
  if memo[bit]>=0:
    return memo[bit]
  elif bit==(1 shl n)-1:
    return 0
  else:
    for i in 0..<n:
      if (bit and (1 shl i))>0:
        continue
      for j in 0..<i:
        if (bit and (1 shl j))>0:        
          continue
        memo[bit]=max(memo[bit], (a[i] xor a[j])+f(bit xor (1 shl i) xor (1 shl j)))
    return memo[bit]

echo f(0)
0