結果

問題 No.545 ママの大事な二人の子供
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-07-21 21:58:43
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 867 bytes
コンパイル時間 3,477 ms
コンパイル使用メモリ 68,852 KB
実行使用メモリ 102,608 KB
最終ジャッジ日時 2023-09-12 13:29:43
合計ジャッジ時間 9,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 RE -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 AC 1,324 ms
102,608 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)
    u.add abs(s[i] + t[idx])

  # echo u
  echo min(u)
0