結果

問題 No.698 ペアでチームを作ろう
ユーザー ikd
提出日時 2018-07-15 19:27:10
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 550 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,169 ms
コンパイル使用メモリ 70,636 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-21 20:15:44
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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 #
raw source code

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