結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー |
![]() |
提出日時 | 2017-07-21 22:02:19 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 935 bytes |
コンパイル時間 | 3,435 ms |
コンパイル使用メモリ | 66,832 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-06-30 01:43:57 |
合計ジャッジ時間 | 4,762 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
/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]
ソースコード
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)