結果

問題 No.545 ママの大事な二人の子供
ユーザー bluemeganebluemegane
提出日時 2018-09-12 09:28:17
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,364 bytes
コンパイル時間 4,718 ms
コンパイル使用メモリ 105,748 KB
実行使用メモリ 33,596 KB
最終ジャッジ日時 2023-09-08 13:41:24
合計ジャッジ時間 8,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,756 KB
testcase_01 AC 63 ms
23,672 KB
testcase_02 AC 63 ms
21,584 KB
testcase_03 AC 63 ms
21,752 KB
testcase_04 AC 63 ms
21,700 KB
testcase_05 AC 63 ms
21,584 KB
testcase_06 AC 64 ms
21,692 KB
testcase_07 AC 63 ms
21,740 KB
testcase_08 AC 63 ms
23,664 KB
testcase_09 AC 63 ms
21,600 KB
testcase_10 AC 64 ms
21,576 KB
testcase_11 AC 64 ms
21,752 KB
testcase_12 AC 65 ms
21,704 KB
testcase_13 AC 64 ms
21,664 KB
testcase_14 AC 69 ms
21,740 KB
testcase_15 AC 65 ms
23,692 KB
testcase_16 AC 66 ms
23,704 KB
testcase_17 AC 64 ms
21,680 KB
testcase_18 AC 67 ms
23,736 KB
testcase_19 AC 68 ms
21,976 KB
testcase_20 AC 71 ms
22,816 KB
testcase_21 AC 65 ms
21,688 KB
testcase_22 AC 96 ms
26,868 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 126 ms
33,596 KB
testcase_26 AC 133 ms
33,564 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 = LowerBound(b, -a[i]);
            if (t >= bL) ans = Math.Min(ans, Math.Abs(a[i] + b[bL -1]));
            else if (t < 0 | t == 0) ans = Math.Min(ans, Math.Abs(a[i] + b[0]));
            else
            {
                ans = Math.Min(ans, Math.Abs(a[i] + b[t]));
                ans = Math.Min(ans, Math.Abs(a[i] + b[t-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;
    }
    public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    public static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}
0