結果

問題 No.545 ママの大事な二人の子供
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-07-21 22:02:19
言語 Nim
(2.0.2)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 4,141 ms
コンパイル使用メモリ 68,588 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2023-09-12 13:30:07
合計ジャッジ時間 5,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 22 ms
5,408 KB
testcase_23 AC 45 ms
8,352 KB
testcase_24 AC 18 ms
5,416 KB
testcase_25 AC 40 ms
8,404 KB
testcase_26 AC 44 ms
8,396 KB
testcase_27 AC 36 ms
7,388 KB
testcase_28 AC 46 ms
8,400 KB
testcase_29 AC 39 ms
8,392 KB
testcase_30 AC 38 ms
7,236 KB
testcase_31 AC 38 ms
7,288 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

{.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 idx = lowerBound(t, -s[i])
    if idx < t.len:
      u.add abs(s[i] + t[idx])
    if 0 < idx:
      u.add abs(s[i] + t[idx-1])

  # echo u
  echo min(u)
0