結果

問題 No.545 ママの大事な二人の子供
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-07-21 22:00:23
言語 Nim
(2.0.2)
結果
TLE  
実行時間 -
コード長 938 bytes
コンパイル時間 3,987 ms
コンパイル使用メモリ 68,792 KB
実行使用メモリ 405,752 KB
最終ジャッジ日時 2023-09-12 13:30:17
合計ジャッジ時間 8,558 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 14 ms
4,436 KB
testcase_17 AC 67 ms
10,292 KB
testcase_18 AC 1,305 ms
102,632 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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], cmp)
    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