結果

問題 No.545 ママの大事な二人の子供
ユーザー bluemeganebluemegane
提出日時 2018-09-12 09:57:06
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,936 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 105,548 KB
実行使用メモリ 33,632 KB
最終ジャッジ日時 2023-09-08 14:26:35
合計ジャッジ時間 5,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,680 KB
testcase_01 AC 63 ms
21,764 KB
testcase_02 AC 63 ms
21,624 KB
testcase_03 AC 63 ms
21,712 KB
testcase_04 AC 65 ms
21,672 KB
testcase_05 AC 67 ms
23,720 KB
testcase_06 AC 63 ms
23,720 KB
testcase_07 AC 65 ms
23,724 KB
testcase_08 AC 65 ms
23,688 KB
testcase_09 AC 65 ms
21,764 KB
testcase_10 AC 67 ms
19,668 KB
testcase_11 AC 65 ms
23,664 KB
testcase_12 AC 64 ms
21,756 KB
testcase_13 AC 64 ms
21,684 KB
testcase_14 AC 64 ms
21,668 KB
testcase_15 AC 66 ms
23,768 KB
testcase_16 AC 66 ms
23,616 KB
testcase_17 AC 65 ms
23,728 KB
testcase_18 AC 70 ms
23,764 KB
testcase_19 AC 72 ms
23,992 KB
testcase_20 AC 74 ms
22,776 KB
testcase_21 AC 66 ms
23,748 KB
testcase_22 AC 99 ms
26,836 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 133 ms
33,528 KB
testcase_26 AC 138 ms
33,632 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.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a0 = (n + 1 ) / 2;   var b0 = n - a0;
        var a = getArray(a0);
        var b = getArray(b0);
        var a2 = putAmB(a);
        var b2 = putAmB(b);
        Array.Sort(b2);
        var ans = getAns(a2, b2);
        Console.WriteLine(ans);
    }
    public static long getAns (long[] a,  long [] b)
    {
        var ans = long.MaxValue;
        var bL = b.Length;
        for (int i = 0; i < a.Length; i++)
        {
            var t = Array.BinarySearch(b, -a[i]);
            if (t >= 0) ans = 0;
            else
            {
                var t2 = ~t;
                if (t2 >= bL) ans = Math.Min(ans, Math.Abs(    a[i] + b[bL - 1]));
                else if (t2 == 0) ans = Math.Min(ans, Math.Abs(  a[i] + b[0]));
                else
                {
                    ans = Math.Min(ans,  Math.Abs(   a[i] + b[t2]));
                    ans = Math.Min(ans, Math.Abs(  a[i] + b[t2 -1]));
                }
            }
        }
        return ans;
    }
    public static long[] putAmB(int[,] a)
    {
        var res = new List<long>();
        var L = a.GetLength(0);
        var imax = 1 << L;
        for (int i = 0; i < imax; i++)
        {
            var amb = 0L;
            for (int j = 0; j < L; j++)
                if (((i >> j) & 1) == 1) amb += a[j, 0];
                else amb -= a[j, 1];
            res.Add(amb);
        }
        var res2 = res.Distinct().ToArray();
        return res2;

    }
    public static int[,] getArray(int n)
    {
        var a = new int[n, 2];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            a[i, 0] = int.Parse(line[0]);
            a[i, 1] = int.Parse(line[1]);
        }
        return a;
    }
}
0