結果

問題 No.545 ママの大事な二人の子供
ユーザー mbanmban
提出日時 2017-07-14 23:35:16
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,141 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 106,112 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-16 20:35:42
合計ジャッジ時間 2,837 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
18,176 KB
testcase_01 AC 28 ms
17,792 KB
testcase_02 AC 28 ms
18,304 KB
testcase_03 AC 27 ms
18,048 KB
testcase_04 AC 27 ms
18,176 KB
testcase_05 AC 28 ms
18,304 KB
testcase_06 AC 28 ms
18,176 KB
testcase_07 AC 28 ms
18,176 KB
testcase_08 AC 29 ms
17,664 KB
testcase_09 AC 27 ms
18,048 KB
testcase_10 AC 28 ms
18,048 KB
testcase_11 AC 27 ms
18,048 KB
testcase_12 AC 28 ms
18,176 KB
testcase_13 AC 28 ms
17,920 KB
testcase_14 AC 28 ms
17,920 KB
testcase_15 AC 28 ms
18,048 KB
testcase_16 AC 28 ms
18,176 KB
testcase_17 AC 29 ms
18,304 KB
testcase_18 AC 29 ms
18,176 KB
testcase_19 AC 30 ms
18,304 KB
testcase_20 AC 32 ms
18,128 KB
testcase_21 AC 27 ms
17,920 KB
testcase_22 AC 49 ms
18,688 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 67 ms
19,584 KB
testcase_26 AC 74 ms
19,584 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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)
                {
                    left = mid;
                }
                else
                {
                    right = 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);
        
    }
}
0