結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー |
![]() |
提出日時 | 2017-07-14 23:31:12 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,131 bytes |
コンパイル時間 | 2,359 ms |
コンパイル使用メモリ | 105,856 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-10-08 00:00:09 |
合計ジャッジ時間 | 3,185 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 RE * 7 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main() { new Magatro().Solve(); } } class Magatro { private int N; private int[] A, B; private List<long> a = new List<long>(), b = new List<long>(); private long ans = long.MaxValue; private void Scan() { N = int.Parse(Console.ReadLine()); A = new int[N]; B = new int[N]; for (int i = 0; i < N; i++) { var line = Console.ReadLine().Split(' '); A[i] = int.Parse(line[0]); B[i] = int.Parse(line[1]); } } private void DFS(long aa, long bb, int left, int right, List<long> t) { if (left == right) { t.Add(aa - bb); return; } DFS(aa + A[left], bb, left + 1, right, t); DFS(aa, bb + B[left], left + 1, right, t); } public void Solve() { Scan(); DFS(0, 0, 0, N / 2, a); DFS(0, 0, N / 2, N, b); b.Sort(); long ans = long.MaxValue; foreach (long l in a) { int left = 0, right = b.Count; while (right - left > 1) { int mid = (left + right) / 2; if (l + b[mid] > 0) { right = mid; } else { left = mid; } } ans = Math.Min(Math.Abs(l + b[left]), ans); left = -1; right = b.Count-1; while (right - left > 1) { int mid = (left + right) / 2; if (l + b[mid] >= 0) { right = mid; } else { left = mid; } } ans = Math.Min(Math.Abs(l + b[right]), ans); } Console.WriteLine(ans); } }