結果

問題 No.545 ママの大事な二人の子供
ユーザー t8m8⛄️
提出日時 2017-07-21 21:53:19
言語 Nim
(2.2.0)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 3,586 ms
コンパイル使用メモリ 66,748 KB
実行使用メモリ 476,440 KB
最終ジャッジ日時 2024-06-30 01:43:52
合計ジャッジ時間 8,262 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 5 RE * 8 TLE * 1 -- * 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 #

import strutils, sequtils, algorithm, future

{.warning[SmallLshouldNotBeUsed]: off.}

when isMainModule:
  var
    n = stdin.readLine.parseInt
    m = n div 2
    a = newSeq[int](n)
    b = newSeq[int](n)

  for i in 0..<n:
    var x = stdin.readLine.split.map(parseInt)
    a[i] = x[0]
    b[i] = x[1]

  var
    s = newSeq[int]()
    t = newSeq[int]()

  for i in 0..<(1 shl m):
    var (x, y) = (0, 0)
    for j in 0..<m:
      if ((i shr j) and 1) == 1:
        x += a[j]
      else:
        y += b[j]
    s.add(x - y)

  for i in 0..<(1 shl n - m):
    var (x, y) = (0, 0)
    for j in 0..<(n - m):
      if ((i shr j) and 1) == 1:
        x += a[m + j]
      else:
        y += b[m + j]
    t.add(x - y)

  t.sort(cmp)
  var u = newSeq[int]()

  for i in 0..<s.len:
    var
      x = if s[i] < 0: -s[i] else: s[i]
      idx = lowerBound(t, x, cmp)
    u.add abs(s[i] + t[idx])

  echo min(u)
0