結果

問題 No.545 ママの大事な二人の子供
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-07-21 21:53:19
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 4,099 ms
コンパイル使用メモリ 68,964 KB
実行使用メモリ 405,924 KB
最終ジャッジ日時 2023-09-12 13:30:01
合計ジャッジ時間 8,906 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 RE -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 AC 4 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1,298 ms
102,504 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
      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