結果

問題 No.545 ママの大事な二人の子供
ユーザー mban
提出日時 2017-07-14 22:39:45
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,015 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 115,572 KB
実行使用メモリ 30,924 KB
最終ジャッジ日時 2024-10-07 23:41:04
合計ジャッジ時間 6,199 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 TLE * 1 -- * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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 long DFS(long aa,long bb,int n)
    {
        if(n == N)
        {
            return Math.Abs(aa - bb);
        }
        long a = DFS(aa + A[n], bb, n + 1);
        long b = DFS(aa, bb + B[n], n + 1);
        return Math.Min(a , b);
    }

    public void Solve()
    {
        Scan();
        Console.WriteLine(DFS(0, 0, 0));
    }
}
0