結果

問題 No.699 ペアでチームを作ろう2
ユーザー むらため
提出日時 2019-01-26 18:33:49
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,887 ms
コンパイル使用メモリ 69,940 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-22 10:10:59
合計ジャッジ時間 2,261 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #
raw source code

import sequtils,algorithm,bitops
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord


let n = scan()
let A = newSeqWith(n,scan())
proc solve(s:int=0,now:int=0) : int =
  if s.popcount == n : return now
  for i in 0..<n:
    if ((1 shl i) and s) > 0 : continue
    for j in (i+1)..<n:
      if ((1 shl j) and s) > 0 : continue
      result .max= solve(s or (1 shl i) or (1 shl j),now xor (A[i] + A[j]))
    # 最高のペアが分かったのでbreakしてよい
    break
echo solve()
0