結果

問題 No.545 ママの大事な二人の子供
ユーザー mbanmban
提出日時 2017-07-14 23:50:15
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,191 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 105,728 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-16 20:46:02
合計ジャッジ時間 4,090 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
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